Skip to content

Commit

Permalink
tests(api): Add ingestProjectScoreCard method to the test manager and…
Browse files Browse the repository at this point in the history
… a lot of tests crash after the new validation contraints
  • Loading branch information
alepefe committed Jan 9, 2025
1 parent 567e11a commit 16fa5b6
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
25 changes: 25 additions & 0 deletions api/test/utils/test-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 16fa5b6

Please sign in to comment.