Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TBCCT-249] feat(api): Ensure that the project scorecards are wiped before new ones are imported #223

Merged
merged 1 commit into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
Loading