Skip to content

Commit

Permalink
Add enums
Browse files Browse the repository at this point in the history
  • Loading branch information
cressie176 committed Jan 7, 2024
1 parent 100d1bd commit 47b15e6
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/dsl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const config = {
await tx.query('DROP FUNCTION IF EXISTS get_vat_rate_v2_aggregate');
await tx.query('DROP TABLE IF EXISTS cgt_rate_v1');
await tx.query('DROP FUNCTION IF EXISTS get_cgt_rate_v1_aggregate');
await tx.query('DROP TYPE IF EXISTS vat_tax_rate');
},
};

Expand All @@ -50,6 +51,57 @@ describe('DSL', () => {
await filby.stop();
});

describe('Enums', () => {
it('should add enums', async (t) => {
await applyYaml(t.name, `
add enums:
- name: vat_tax_rate
values:
- standard
- reduced
- zero
`);
const { rows: labels } = await filby.withTransaction((tx) => tx.query("SELECT enumlabel AS label FROM pg_enum WHERE enumtypid = 'vat_tax_rate'::regtype"));

eq(labels.length, 3);
deq(labels[0], { label: 'standard' });
deq(labels[1], { label: 'reduced' });
deq(labels[2], { label: 'zero' });
});

it('should require a name', async (t) => {
await rejects(() => applyYaml(t.name, `
add enums:
- values:
- standard
- reduced
- zero
`), (err) => {
match(err.message, new RegExp("^001.should-require-a-name.yaml: /add_enums/0 must have required property 'name'"));
return true;
});
});

it('should require at least one value', async (t) => {
await rejects(() => applyYaml(t.name, `
add enums:
- name: vat_tax_rate
`), (err) => {
match(err.message, new RegExp("^001.should-require-at-least-one-value.yaml: /add_enums/0 must have required property 'values'"));
return true;
});

await rejects(() => applyYaml(t.name, `
add enums:
- name: vat_tax_rate
values:
`), (err) => {
match(err.message, new RegExp('^001.should-require-at-least-one-value.yaml: /add_enums/0/values must be an array'));
return true;
});
});
});

describe('Projections', () => {
it('should add projections', async (t) => {
await applyYaml(t.name, `
Expand Down

0 comments on commit 47b15e6

Please sign in to comment.