Skip to content

Commit a73bfa6

Browse files
committed
Empty collections instead of drop them for avoiding random tests failures
1 parent 60183a9 commit a73bfa6

File tree

3 files changed

+3
-16
lines changed

3 files changed

+3
-16
lines changed

src/Contexts/Backoffice/Courses/infrastructure/persistence/BackofficeMongoConfigFactory.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Contexts/Mooc/Courses/infrastructure/persistence/MongoCourseRepository.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export class MongoCourseRepository extends MongoRepository<Course> implements Co
1111

1212
public async search(id: CourseId): Promise<Nullable<Course>> {
1313
const collection = await this.collection();
14-
1514
const document = await collection.findOne({ _id: id.value });
1615

1716
return document ? Course.fromPrimitives({ ...document, id: id.value }) : null;

tests/Contexts/Shared/infrastructure/mongo/MongoEnvironmentArranger.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@ export class MongoEnvironmentArranger extends EnvironmentArranger {
1212

1313
protected async cleanDatabase(): Promise<void> {
1414
const collections = await this.collections();
15+
const client = await this.client();
1516

1617
for (const collection of collections) {
17-
await (await this.client()).db().dropCollection(collection);
18+
await client.db().collection(collection).deleteMany({});
1819
}
1920
}
2021

2122
private async collections(): Promise<string[]> {
2223
const client = await this.client();
23-
const collections = await client
24-
.db()
25-
.listCollections(undefined, { nameOnly: true })
26-
.toArray();
24+
const collections = await client.db().listCollections(undefined, { nameOnly: true }).toArray();
2725

2826
return collections.map(collection => collection.name);
2927
}

0 commit comments

Comments
 (0)