Skip to content

Commit

Permalink
Use postgres error names in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cressie176 committed Jan 27, 2024
1 parent ad0f51e commit cbf5933
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"lint-staged": "^15.2.0",
"nyc": "^15.1.0",
"object-path-immutable": "^4.1.2",
"pg-error-enum": "^0.7.0",
"zunit": "^4.0.2"
},
"lint-staged": {
Expand All @@ -66,4 +67,4 @@
"url": "https://github.com/acuminous/filby/issues"
},
"homepage": "https://acuminous.github.io/filby"
}
}
15 changes: 8 additions & 7 deletions test/database-schema.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { ok, strictEqual: eq, deepEqual: deq, rejects, match } = require('node:assert');
const { describe, it, before, beforeEach, after, afterEach } = require('zunit');
const { PostgresError: { UNIQUE_VIOLATION, NOT_NULL_VIOLATION, FOREIGN_KEY_VIOLATION } } = require('pg-error-enum');

const TestFilby = require('./TestFilby');

Expand Down Expand Up @@ -56,7 +57,7 @@ describe('Database Schema', () => {
await tx.query("INSERT INTO fby_projection (name, version) VALUES ('DUPLICATE', 1)");
});
}, (err) => {
eq(err.code, '23505');
eq(err.code, UNIQUE_VIOLATION);
return true;
});
});
Expand All @@ -67,7 +68,7 @@ describe('Database Schema', () => {
await tx.query('INSERT INTO fby_projection (name, version) VALUES (NULL, 1)');
});
}, (err) => {
eq(err.code, '23502');
eq(err.code, NOT_NULL_VIOLATION);
return true;
});
});
Expand All @@ -78,7 +79,7 @@ describe('Database Schema', () => {
await tx.query("INSERT INTO fby_projection (name, version) VALUES ('OK', NULL)");
});
}, (err) => {
eq(err.code, '23502');
eq(err.code, NOT_NULL_VIOLATION);
return true;
});
});
Expand All @@ -105,7 +106,7 @@ describe('Database Schema', () => {
await tx.query('INSERT INTO fby_projection_entity (projection_id, entity_id) VALUES (1, 1)');
await tx.query('DELETE FROM fby_entity');
}), (err) => {
eq(err.code, '23503');
eq(err.code, FOREIGN_KEY_VIOLATION);
return true;
});
});
Expand Down Expand Up @@ -140,7 +141,7 @@ describe('Database Schema', () => {
await tx.query("INSERT INTO fby_hook (name, event, projection_id) VALUES ('change 1', 'ADD_CHANGE_SET', 1)");
});
}, (err) => {
eq(err.code, '23505');
eq(err.code, UNIQUE_VIOLATION);
return true;
});
});
Expand Down Expand Up @@ -200,7 +201,7 @@ describe('Database Schema', () => {
(3, 'Park updates', '2023-01-01T00:00:00.000Z')`);
});
}, (err) => {
eq(err.code, '23505');
eq(err.code, UNIQUE_VIOLATION);
return true;
});
});
Expand All @@ -211,7 +212,7 @@ describe('Database Schema', () => {
await tx.query("INSERT INTO fby_change_set (id, description, effective) VALUES (1, 'Park updates', NULL)");
});
}, (err) => {
eq(err.code, '23502');
eq(err.code, NOT_NULL_VIOLATION);
return true;
});
});
Expand Down
7 changes: 4 additions & 3 deletions test/dsl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { ok, strictEqual: eq, deepEqual: deq, rejects, match } = require('node:as
const { describe, it, before, beforeEach, after, afterEach } = require('zunit');
const YAML = require('yaml');
const op = require('object-path-immutable');
const { PostgresError: { INVALID_NAME, SYNTAX_ERROR, CHECK_VIOLATION } } = require('pg-error-enum');

const TestFilby = require('./TestFilby');
const { table } = require('../lib/helpers');
Expand Down Expand Up @@ -168,7 +169,7 @@ describe('DSL', () => {

it('should escape values', async (t) => {
await rejects(applyYaml(t.name, transform(ADD_ENUM).set('0.values.0', "pwned'); RAISE EXCEPTION $💀$You have been pwned!$💀$; CREATE TYPE pwned AS ENUM ('standard")), (err) => {
eq(err.code, '42602');
eq(err.code, INVALID_NAME);
return true;
});
});
Expand Down Expand Up @@ -400,7 +401,7 @@ describe('DSL', () => {

it('should reject invalid field types', async (t) => {
await rejects(() => applyYaml(t.name, transform(ADD_ENTITY).set('0.fields.0.type', 'INVALID TYPE')), (err) => {
eq(err.code, '42601');
eq(err.code, SYNTAX_ERROR);
return true;
});
});
Expand Down Expand Up @@ -488,7 +489,7 @@ describe('DSL', () => {
transform(ADD_ENTITY).merge('0.checks', { max_rate: '(rate <= 1)' }),
transform(ADD_CHANGE_SET_1).set('0.frames.0.data.0.rate', 1.1),
), (err) => {
eq(err.code, '23514');
eq(err.code, CHECK_VIOLATION);
return true;
});
});
Expand Down

0 comments on commit cbf5933

Please sign in to comment.