Skip to content

Commit

Permalink
[feature] Accept empty models (#33)
Browse files Browse the repository at this point in the history
```
Test Suites: 4 passed, 4 total
Tests:       23 passed, 23 total
Snapshots:   0 total
Time:        1.143 s
Ran all test suites.
```
  • Loading branch information
zbigh committed Feb 5, 2024
1 parent f8a4fa2 commit eb8c654
Show file tree
Hide file tree
Showing 6 changed files with 16,412 additions and 2,968 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.15
21.6.1
48 changes: 48 additions & 0 deletions __tests__/wire/processNotification.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,51 @@ it("returns false on a dubled idempotency key", () => {
]);
expect(result).toBe(false);
});

it("returns false if idempotency key has been received already", () => {
const notification = [
"Article",
1,
"created",
{ id: 1, loco: { idempotency_key: "aea41272f11ea5c75db8ba589156771e" } },
];
const result = processNotification(notification);
expect(result).toBe(false);
});

it("sends notification to notification center if model is undefined", () => {
const notification = [
"UnknownModel",
1,
"created",
{ id: 1, loco: { idempotency_key: "aea41272f11ea5c75db8ba589156771f" } },
];
const notificationCenter = jest.fn();
const result = processNotification(notification, { notificationCenter });
expect(result).toBe(false);
expect(notificationCenter).toHaveBeenCalledWith({
type: "UnknownModel created",
payload: {
id: 1,
loco: { idempotency_key: "aea41272f11ea5c75db8ba589156771f" },
},
});
});

it("sends notification to notification center if model is defined", () => {
const notification = [
"Article",
1,
"created",
{ id: 1, loco: { idempotency_key: "aea41272f11ea5c75db8ba589156771g" } },
];
const notificationCenter = jest.fn();
processNotification(notification, { notificationCenter });
expect(notificationCenter).toHaveBeenCalledWith({
type: "Article created",
payload: {
id: 1,
loco: { idempotency_key: "aea41272f11ea5c75db8ba589156771g" },
},
});
});
2 changes: 1 addition & 1 deletion dist/loco.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/loco.js.map

Large diffs are not rendered by default.

0 comments on commit eb8c654

Please sign in to comment.