Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cressie176 committed Jan 7, 2024
1 parent b3acd12 commit d73b2b3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 50 deletions.
21 changes: 2 additions & 19 deletions test/TestReferenceDataFramework.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,24 @@ const noop = () => { };
module.exports = class TestReferenceDataFramework extends ReferenceDataFramework {

#nukeCustomObjects;
#wipeCustomData;

constructor(config) {
super(config);
this.#nukeCustomObjects = config.nukeCustomObjects || noop;
this.#wipeCustomData = config.wipeCustomData || noop;
}

async reset() {
await this.withTransaction(async (tx) => {
await this.#nukeCustomObjects(tx);
await this.#wipeRdfData(tx);
})
await this.init();
await this.wipe();
}

async wipe() {
await this.withTransaction(async (tx) => {
await this.#wipeCustomData(tx);
await this.#nukeCustomObjects(tx);
await this.#wipeRdfData(tx);
})
}

async nukeCustomObjects() {
return this.withTransaction((tx) => {
return this.#nukeCustomObjects(tx);
})
}

async wipeRdfData() {
return this.withTransaction((tx) => {
return this.#wipeRdfData(tx);
})
}

async #wipeRdfData(tx) {
await tx.query('DELETE FROM rdf_notification');
await tx.query('DELETE FROM rdf_hook');
Expand Down
10 changes: 2 additions & 8 deletions test/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ const config = {
await tx.query('DROP TABLE IF EXISTS vat_rate_v1');
await tx.query('DROP FUNCTION IF EXISTS get_vat_rate_v1_aggregate');
await tx.query('DROP TYPE IF EXISTS tax_rate_type');
},
wipeCustomData: async (tx) => {
await tx.query('DELETE FROM vat_rate_v1');
}
}

Expand All @@ -31,15 +28,12 @@ describe('API', () => {

before(async () => {
rdf = new TestReferenceDataFramework(config);
await rdf.init();
await rdf.nukeCustomObjects();
await rdf.wipeRdfData();
await rdf.reset;
})

beforeEach(async () => {
rdf.removeAllListeners();
await rdf.nukeCustomObjects();
await rdf.wipeRdfData();
await rdf.wipe();
})

afterEach(async () => {
Expand Down
12 changes: 2 additions & 10 deletions test/dsl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ 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');
},
wipeCustomData: async (tx) => {
await tx.query('DELETE FROM vat_rate_v1');
await tx.query('DELETE FROM vat_rate_v2');
await tx.query('DELETE FROM cgt_rate_v1');
}
}

Expand All @@ -39,15 +34,12 @@ describe('DSL', () => {
before(async () => {
deleteMigrations();
rdf = new TestReferenceDataFramework(config);
await rdf.init();
await rdf.nukeCustomObjects();
await rdf.wipeRdfData();
await rdf.reset();
})

beforeEach(async () => {
deleteMigrations();
await rdf.nukeCustomObjects();
await rdf.wipeRdfData();
await rdf.wipe();
})

after(async () => {
Expand Down
10 changes: 2 additions & 8 deletions test/notifications.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ const config = {
},
nukeCustomObjects: async (tx) => {
await tx.query('DROP TABLE IF EXISTS vat_rate_v1');
},
wipeCustomData: async (tx) => {
await tx.query('DELETE FROM vat_rate_v1');
}
}

Expand All @@ -29,15 +26,12 @@ describe('Notifications', () => {

before(async () => {
rdf = new TestReferenceDataFramework(config);
await rdf.init();
await rdf.nukeCustomObjects();
await rdf.wipeRdfData();
await rdf.reset();
})

beforeEach(async () => {
rdf.removeAllListeners();
await rdf.nukeCustomObjects();
await rdf.wipeRdfData();
await rdf.wipe();
})

afterEach(async () => {
Expand Down
7 changes: 2 additions & 5 deletions test/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ describe('Schema', () => {

before(async () => {
rdf = new TestReferenceDataFramework(config);
await rdf.init();
await rdf.nukeCustomObjects();
await rdf.wipeRdfData();
await rdf.reset();
})

beforeEach(async () => {
await rdf.nukeCustomObjects();
await rdf.wipeRdfData();
await rdf.wipe();
})

after(async () => {
Expand Down

0 comments on commit d73b2b3

Please sign in to comment.