-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import project scorecard functionality
- Loading branch information
1 parent
da5615a
commit 3976668
Showing
10 changed files
with
245 additions
and
8 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
api/src/modules/import/dtos/excel-projects-scorecard.dto .ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ECOSYSTEM } from '@shared/entities/ecosystem.enum'; | ||
|
||
export type ExcelProjectScorecard = { | ||
country: string; | ||
country_code: string; | ||
ecosystem: ECOSYSTEM; | ||
legal_feasibility: number; | ||
implementation_risk_score: number; | ||
availability_of_experienced_labor: number; | ||
security_rating: number; | ||
availability_of_alternative_funding: number; | ||
biodiversity_benefit: number; | ||
social_feasibility: number; | ||
coastal_protection_benefit: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { TestManager } from '../../utils/test-manager'; | ||
import { HttpStatus } from '@nestjs/common'; | ||
import { adminContract } from '@shared/contracts/admin.contract'; | ||
import { ROLES } from '@shared/entities/users/roles.enum'; | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
import { ProjectScorecard } from '@shared/entities/project-scorecard.entity'; | ||
|
||
describe('Import Tests', () => { | ||
let testManager: TestManager; | ||
let testUserToken: string; | ||
const testFilePath = path.join( | ||
__dirname, | ||
'../../../../data/excel/data_ingestion_project_scorecard.xlsm', | ||
); | ||
const fileBuffer = fs.readFileSync(testFilePath); | ||
|
||
beforeAll(async () => { | ||
testManager = await TestManager.createTestManager(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
const { jwtToken } = await testManager.setUpTestUser(); | ||
testUserToken = jwtToken; | ||
}); | ||
|
||
afterEach(async () => { | ||
await testManager.clearDatabase(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testManager.close(); | ||
}); | ||
|
||
describe('Import Auth', () => { | ||
it('should throw an error if no file is sent', async () => { | ||
const response = await testManager | ||
.request() | ||
.post(adminContract.uploadProjectScorecard.path) | ||
.set('Authorization', `Bearer ${testUserToken}`) | ||
.send(); | ||
|
||
expect(response.status).toBe(HttpStatus.BAD_REQUEST); | ||
expect(response.body.errors[0].title).toBe('File is required'); | ||
}); | ||
|
||
it('should throw an error if the user is not an admin', async () => { | ||
const nonAdminUser = await testManager | ||
.mocks() | ||
.createUser({ role: ROLES.PARTNER, email: '[email protected]' }); | ||
|
||
const { jwtToken } = await testManager.logUserIn(nonAdminUser); | ||
|
||
const response = await testManager | ||
.request() | ||
.post(adminContract.uploadProjectScorecard.path) | ||
.set('Authorization', `Bearer ${jwtToken}`) | ||
.attach('file', fileBuffer, 'data_ingestion_WIP.xlsm'); | ||
|
||
expect(response.status).toBe(HttpStatus.FORBIDDEN); | ||
}); | ||
}); | ||
describe('Import Data', () => { | ||
it('should import project scorecard data from an excel file', async () => { | ||
await testManager.ingestCountries(); | ||
await testManager | ||
.request() | ||
.post(adminContract.uploadProjectScorecard.path) | ||
.set('Authorization', `Bearer ${testUserToken}`) | ||
.attach('file', fileBuffer, 'data_ingestion_project_scorecard.xlsm'); | ||
|
||
const projectScorecard = await testManager | ||
.getDataSource() | ||
.getRepository(ProjectScorecard) | ||
.find(); | ||
|
||
expect(projectScorecard).toHaveLength(208); | ||
}, 30000); | ||
}); | ||
}); |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters