Skip to content

Commit

Permalink
fix subscribeStash test
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Nov 27, 2024
1 parent 98f83d9 commit 88f1ccd
Showing 1 changed file with 57 additions and 71 deletions.
128 changes: 57 additions & 71 deletions packages/stash/src/actions/subscribeStash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,72 +39,64 @@ describe("subscribeStash", () => {
vi.advanceTimersToNextTimer();

expect(subscriber).toHaveBeenCalledTimes(1);
expect(subscriber).toHaveBeenNthCalledWith(1, {
config: {},
records: {
namespace1: {
table1: {
"0x00": {
prev: undefined,
current: { a: "0x00", b: 1n, c: 2 },
},
},
expect(subscriber).toHaveBeenCalledWith({
type: "records",
updates: [
{
table: config.tables.namespace1__table1,
key: { a: "0x00" },
previous: undefined,
current: { a: "0x00", b: 1n, c: 2 },
},
},
],
});

setRecord({ stash, table: config.tables.namespace2__table2, key: { a: "0x01" }, value: { b: 1n, c: 2 } });
vi.advanceTimersToNextTimer();

expect(subscriber).toHaveBeenCalledTimes(2);
expect(subscriber).toHaveBeenNthCalledWith(2, {
config: {},
records: {
namespace2: {
table2: {
"0x01": {
prev: undefined,
current: { a: "0x01", b: 1n, c: 2 },
},
},
type: "records",
updates: [
{
table: config.tables.namespace2__table2,
key: { a: "0x01" },
previous: undefined,
current: { a: "0x01", b: 1n, c: 2 },
},
},
],
});

setRecord({ stash, table: config.tables.namespace2__table2, key: { a: "0x01" }, value: { b: 1n, c: 3 } });
vi.advanceTimersToNextTimer();

expect(subscriber).toHaveBeenCalledTimes(3);
expect(subscriber).toHaveBeenNthCalledWith(3, {
config: {},
records: {
namespace2: {
table2: {
"0x01": {
prev: { a: "0x01", b: 1n, c: 2 },
current: { a: "0x01", b: 1n, c: 3 },
},
},
type: "records",
updates: [
{
table: config.tables.namespace2__table2,
key: { a: "0x01" },
previous: { a: "0x01", b: 1n, c: 2 },
current: { a: "0x01", b: 1n, c: 3 },
},
},
],
});

deleteRecord({ stash, table: config.tables.namespace2__table2, key: { a: "0x01" } });
vi.advanceTimersToNextTimer();

expect(subscriber).toHaveBeenCalledTimes(4);
expect(subscriber).toHaveBeenNthCalledWith(4, {
config: {},
records: {
namespace2: {
table2: {
"0x01": {
prev: { a: "0x01", b: 1n, c: 3 },
current: undefined,
},
},
type: "records",
updates: [
{
table: config.tables.namespace2__table2,
key: { a: "0x01" },
previous: { a: "0x01", b: 1n, c: 3 },
current: undefined,
},
},
],
});
});

Expand Down Expand Up @@ -134,53 +126,47 @@ describe("subscribeStash", () => {

expect(subscriber).toHaveBeenCalledTimes(1);
expect(subscriber).toHaveBeenNthCalledWith(1, {
config: {},
records: {
app: {
config: {
"": {
prev: undefined,
current: { enabled: true },
},
},
type: "records",
updates: [
{
table: config.tables.app__config,
key: {},
previous: undefined,
current: { enabled: true },
},
},
],
});

setRecord({ stash, table: config.tables.app__config, key: {}, value: { enabled: false } });
vi.advanceTimersToNextTimer();

expect(subscriber).toHaveBeenCalledTimes(2);
expect(subscriber).toHaveBeenNthCalledWith(2, {
config: {},
records: {
app: {
config: {
"": {
prev: { enabled: true },
current: { enabled: false },
},
},
type: "records",
updates: [
{
table: config.tables.app__config,
key: {},
previous: { enabled: true },
current: { enabled: false },
},
},
],
});

deleteRecord({ stash, table: config.tables.app__config, key: {} });
vi.advanceTimersToNextTimer();

expect(subscriber).toHaveBeenCalledTimes(3);
expect(subscriber).toHaveBeenNthCalledWith(3, {
config: {},
records: {
app: {
config: {
"": {
prev: { enabled: false },
current: undefined,
},
},
type: "records",
updates: [
{
table: config.tables.app__config,
key: {},
previous: { enabled: false },
current: undefined,
},
},
],
});
});
});

0 comments on commit 88f1ccd

Please sign in to comment.