From 351138882029f217ecd808d464781aed5dbe5f3d Mon Sep 17 00:00:00 2001 From: Alejandro Peralta Date: Thu, 9 Jan 2025 14:08:03 +0100 Subject: [PATCH] tests(api): Add ingestProjectScoreCard method to the test manager and a lot of tests crash after the new validation contraints --- .../custom-projects-create.spec.ts | 1 + .../custom-projects-delete.spec.ts | 1 + .../custom-projects-read.spec.ts | 1 + .../custom-projects-save.spec.ts | 1 + .../custom-projects-setup.spec.ts | 1 + .../custom-projects-update.spec.ts | 1 + api/test/integration/import/import.spec.ts | 1 + api/test/utils/test-manager.ts | 25 +++++++++++++++++++ 8 files changed, 32 insertions(+) diff --git a/api/test/integration/custom-projects/custom-projects-create.spec.ts b/api/test/integration/custom-projects/custom-projects-create.spec.ts index c532783f..32723e6e 100644 --- a/api/test/integration/custom-projects/custom-projects-create.spec.ts +++ b/api/test/integration/custom-projects/custom-projects-create.spec.ts @@ -8,6 +8,7 @@ describe('Create Custom Projects - Setup', () => { testManager = await TestManager.createTestManager(); const { jwtToken } = await testManager.setUpTestUser(); await testManager.ingestCountries(); + await testManager.ingestProjectScoreCards(jwtToken); await testManager.ingestExcel(jwtToken); }); diff --git a/api/test/integration/custom-projects/custom-projects-delete.spec.ts b/api/test/integration/custom-projects/custom-projects-delete.spec.ts index e84e0e1e..ebe26343 100644 --- a/api/test/integration/custom-projects/custom-projects-delete.spec.ts +++ b/api/test/integration/custom-projects/custom-projects-delete.spec.ts @@ -15,6 +15,7 @@ describe('Delete Custom projects', () => { beforeEach(async () => { ({ jwtToken, user } = await testManager.setUpTestUser()); await testManager.ingestCountries(); + await testManager.ingestProjectScoreCards(jwtToken); await testManager.ingestExcel(jwtToken); }); diff --git a/api/test/integration/custom-projects/custom-projects-read.spec.ts b/api/test/integration/custom-projects/custom-projects-read.spec.ts index b599e401..657cf51a 100644 --- a/api/test/integration/custom-projects/custom-projects-read.spec.ts +++ b/api/test/integration/custom-projects/custom-projects-read.spec.ts @@ -15,6 +15,7 @@ describe('Read Custom projects', () => { beforeEach(async () => { ({ jwtToken, user } = await testManager.setUpTestUser()); await testManager.ingestCountries(); + await testManager.ingestProjectScoreCards(jwtToken); await testManager.ingestExcel(jwtToken); }); diff --git a/api/test/integration/custom-projects/custom-projects-save.spec.ts b/api/test/integration/custom-projects/custom-projects-save.spec.ts index 2379e672..4abb38ce 100644 --- a/api/test/integration/custom-projects/custom-projects-save.spec.ts +++ b/api/test/integration/custom-projects/custom-projects-save.spec.ts @@ -12,6 +12,7 @@ describe('Snapshot Custom Projects', () => { const { jwtToken } = await testManager.setUpTestUser(); token = jwtToken; await testManager.ingestCountries(); + await testManager.ingestProjectScoreCards(jwtToken); await testManager.ingestExcel(jwtToken); }); diff --git a/api/test/integration/custom-projects/custom-projects-setup.spec.ts b/api/test/integration/custom-projects/custom-projects-setup.spec.ts index 83fae0e1..6f92c71a 100644 --- a/api/test/integration/custom-projects/custom-projects-setup.spec.ts +++ b/api/test/integration/custom-projects/custom-projects-setup.spec.ts @@ -15,6 +15,7 @@ describe('Create Custom Projects - Setup', () => { const { jwtToken: token } = await testManager.setUpTestUser(); jwtToken = token; await testManager.ingestCountries(); + await testManager.ingestProjectScoreCards(jwtToken); await testManager.ingestExcel(jwtToken); }); diff --git a/api/test/integration/custom-projects/custom-projects-update.spec.ts b/api/test/integration/custom-projects/custom-projects-update.spec.ts index ed5aaf79..0c76df26 100644 --- a/api/test/integration/custom-projects/custom-projects-update.spec.ts +++ b/api/test/integration/custom-projects/custom-projects-update.spec.ts @@ -14,6 +14,7 @@ describe('Update custom projects', () => { beforeEach(async () => { ({ jwtToken, user } = await testManager.setUpTestUser()); await testManager.ingestCountries(); + await testManager.ingestProjectScoreCards(jwtToken); await testManager.ingestExcel(jwtToken); }); diff --git a/api/test/integration/import/import.spec.ts b/api/test/integration/import/import.spec.ts index 60af4827..1a3b91eb 100644 --- a/api/test/integration/import/import.spec.ts +++ b/api/test/integration/import/import.spec.ts @@ -62,6 +62,7 @@ describe('Import Tests', () => { describe('Import Data', () => { it('should import cost data from an excel file', async () => { await testManager.ingestCountries(); + await testManager.ingestProjectScoreCards(testUserToken); await testManager .request() .post(adminContract.uploadFile.path) diff --git a/api/test/utils/test-manager.ts b/api/test/utils/test-manager.ts index 28e6d2c1..ddfc4d3e 100644 --- a/api/test/utils/test-manager.ts +++ b/api/test/utils/test-manager.ts @@ -121,6 +121,31 @@ export class TestManager { await this.dataSource.query(geoCountriesSql); } + async ingestProjectScoreCards(jwtToken: string) { + const countriesPresent = await this.dataSource + .getRepository(Country) + .find(); + if (!countriesPresent.length) { + throw new Error( + 'No Countries present in the DB, cannot ingest Excel data for tests', + ); + } + const testFilePath = path.join( + __dirname, + '../../../data/excel/data_ingestion_project_scorecard.xlsm', + ); + const fileBuffer = fs.readFileSync(testFilePath); + const upload = await this.request() + .post(adminContract.uploadProjectScorecard.path) + .set('Authorization', `Bearer ${jwtToken}`) + .attach('file', fileBuffer, 'data_ingestion_project_scorecard.xlsm'); + if (upload.status !== 201) { + throw new Error( + 'Failed to upload data_ingestion_project_scorecard.xlsm file for tests', + ); + } + } + async ingestExcel(jwtToken: string) { const countriesPresent = await this.dataSource .getRepository(Country)