Skip to content

Commit

Permalink
feat(api): Ensure that the project scorecards are wiped before new on…
Browse files Browse the repository at this point in the history
…es are imported
  • Loading branch information
alepefe committed Jan 12, 2025
1 parent 14be8ec commit 6540f56
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
6 changes: 5 additions & 1 deletion api/src/modules/import/import.repostiory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export class ImportRepository {
constructor(private readonly dataSource: DataSource) {}

async importProjectScorecard(projectScorecards: ProjectScorecard[]) {
return this.dataSource.transaction(async (manager) => {
return this.dataSource.transaction('READ COMMITTED', async (manager) => {
// Wipe current project scorecards
await manager.clear(ProjectScorecard);

// Insert
await manager.save(projectScorecards);
});
}
Expand Down
38 changes: 38 additions & 0 deletions api/test/integration/import/import.repository.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ProjectScorecard } from '@shared/entities/project-scorecard.entity';
import { TestManager } from 'api/test/utils/test-manager';

describe('Import Repository', () => {
let testManager: TestManager;
let jwtToken: string;

beforeAll(async () => {
testManager = await TestManager.createTestManager();
const response = await testManager.setUpTestUser();
jwtToken = response.jwtToken;
});

afterEach(async () => {
await testManager.clearDatabase();
});

afterAll(async () => {
await testManager.close();
});

it('should wipe previous project scorecards before importing new ones', async () => {
// Given
await testManager.ingestCountries();
await testManager.ingestProjectScoreCards(jwtToken);
const scorecardRepository =
testManager.dataSource.getRepository(ProjectScorecard);

const scorecardCount = await scorecardRepository.count();

// When
await testManager.ingestProjectScoreCards(jwtToken);
const latestScorecardCount = await scorecardRepository.count();

// Then
expect(scorecardCount).toEqual(latestScorecardCount);
});
});

0 comments on commit 6540f56

Please sign in to comment.