diff options
author | 2024-03-19 17:10:33 +0000 | |
---|---|---|
committer | 2024-03-19 17:10:33 +0000 | |
commit | 2ebcf94d0af5ac789c61b4190dea0ad6a402a6ea (patch) | |
tree | ec1e31d444737ea0465f1d812ad9cace638ce8cb /packages/db/test/unit/column-queries.test.js | |
parent | 4268d389fcb4de852bf7bcbb65fabceec395a849 (diff) | |
download | astro-2ebcf94d0af5ac789c61b4190dea0ad6a402a6ea.tar.gz astro-2ebcf94d0af5ac789c61b4190dea0ad6a402a6ea.tar.zst astro-2ebcf94d0af5ac789c61b4190dea0ad6a402a6ea.zip |
chore(db): Add missing github-slugger dependency & tests (#10405)
* chore: add missing github-slugger dependency
* test: add column-queries data loss tests
* chore: remove unused vars
* test: assert length rather than message content
Diffstat (limited to 'packages/db/test/unit/column-queries.test.js')
-rw-r--r-- | packages/db/test/unit/column-queries.test.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/packages/db/test/unit/column-queries.test.js b/packages/db/test/unit/column-queries.test.js index a26425817..0d0dbb0f4 100644 --- a/packages/db/test/unit/column-queries.test.js +++ b/packages/db/test/unit/column-queries.test.js @@ -105,6 +105,65 @@ describe('column queries', () => { expect(queries).to.deep.equal([]); }); + it('should return warning if column type change introduces data loss', async () => { + const blogInitial = tableSchema.parse({ + ...userInitial, + columns: { + date: column.text(), + }, + }); + const blogFinal = tableSchema.parse({ + ...userInitial, + columns: { + date: column.date(), + }, + }); + const { queries, confirmations } = await userChangeQueries(blogInitial, blogFinal); + expect(queries).to.deep.equal([ + 'DROP TABLE "Users"', + 'CREATE TABLE "Users" (_id INTEGER PRIMARY KEY, "date" text NOT NULL)', + ]); + expect(confirmations.length).to.equal(1); + }); + + it('should return warning if new required column added', async () => { + const blogInitial = tableSchema.parse({ + ...userInitial, + columns: {}, + }); + const blogFinal = tableSchema.parse({ + ...userInitial, + columns: { + date: column.date({ optional: false }), + }, + }); + const { queries, confirmations } = await userChangeQueries(blogInitial, blogFinal); + expect(queries).to.deep.equal([ + 'DROP TABLE "Users"', + 'CREATE TABLE "Users" (_id INTEGER PRIMARY KEY, "date" text NOT NULL)', + ]); + expect(confirmations.length).to.equal(1); + }); + + it('should return warning if non-number primary key with no default added', async () => { + const blogInitial = tableSchema.parse({ + ...userInitial, + columns: {}, + }); + const blogFinal = tableSchema.parse({ + ...userInitial, + columns: { + id: column.text({ primaryKey: true }), + }, + }); + const { queries, confirmations } = await userChangeQueries(blogInitial, blogFinal); + expect(queries).to.deep.equal([ + 'DROP TABLE "Users"', + 'CREATE TABLE "Users" ("id" text PRIMARY KEY)', + ]); + expect(confirmations.length).to.equal(1); + }); + it('should be empty when type updated to same underlying SQL type', async () => { const blogInitial = tableSchema.parse({ ...userInitial, |