Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/pg/test/db/dbWrite.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ describe('postgres', () => {
verDefault: 'current_timestamp',
}),
);

store.use(
'sfWrite',
pg({
table: 'sfWrite',
idCol: 'id',
verCol: 'updatedAt',
schema: {
types: {
id: 'uuid',
write: 'jsonb',
updatedAt: 'int8',
},
},
verDefault: 'current_timestamp',
}),
);
});

afterEach(async () => {
Expand Down Expand Up @@ -191,4 +208,22 @@ describe('postgres', () => {
RETURNING *, "id" AS "$key", current_timestamp AS "$ver"`;
expectSql(mockQuery.mock.calls[0][0], sqlQuery);
});

test('jsonb_null_patch_uses_plain_null', async () => {
await store.write('sfWrite.foo', {
write: { WhatId: { $val: null } },
});

const sqlQuery = sql`
UPDATE "sfWrite" SET
"write" = case jsonb_typeof("write")
when 'object' then "write"
else '{}'::jsonb
end || jsonb_build_object(${'WhatId'}::text, ${'{"WhatId":null}'}::jsonb),
"updatedAt" = default
WHERE "id" = ${'foo'}
RETURNING *, "id" AS "$key", current_timestamp AS "$ver"`;

expectSql(mockQuery.mock.calls[0][0], sqlQuery);
});
});
Loading