Skip to content

Commit 7a064dc

Browse files
committed
Use the same describe style at test suite
1 parent 36f44bf commit 7a064dc

File tree

10 files changed

+94
-94
lines changed

10 files changed

+94
-94
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import MongoConfig from '../../../../Shared/infrastructure/persistence/mongo/Mon
33

44
export class BackofficeMongoConfigFactory {
55
static createConfig(): MongoConfig {
6-
console.log(config.get('mongo.url'));
76
return {
87
url: config.get('mongo.url')
98
};

tests/Contexts/Backoffice/Courses/infrastructure/ElasticBackofficeCourseRepository.test.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,25 @@ const environmentArranger: Promise<EnvironmentArranger> = container.get(
1111
'Backoffice.Backend.ElasticEnvironmentArranger'
1212
);
1313

14-
function sort(backofficeCourse1: BackofficeCourse, backofficeCourse2: BackofficeCourse): number {
15-
return backofficeCourse1?.id?.value.localeCompare(backofficeCourse2?.id?.value);
16-
}
17-
1814
afterEach(async () => {
1915
await (await environmentArranger).arrange();
2016
});
2117

22-
describe('Search all courses', () => {
23-
it('should return the existing courses', async () => {
24-
const courses = [BackofficeCourseMother.random(), BackofficeCourseMother.random()];
18+
describe('ElasticBackofficeCourseRepository', () => {
19+
describe('#searchAll', () => {
20+
it('should return the existing courses', async () => {
21+
const courses = [BackofficeCourseMother.random(), BackofficeCourseMother.random()];
2522

26-
await Promise.all(courses.map(async course => repository.save(course)));
23+
await Promise.all(courses.map(async course => repository.save(course)));
2724

28-
const expectedCourses = await repository.searchAll();
25+
const expectedCourses = await repository.searchAll();
2926

30-
expect(courses.length).toEqual(expectedCourses.length);
31-
expect(courses.sort(sort)).toEqual(expectedCourses.sort(sort));
27+
expect(courses.length).toEqual(expectedCourses.length);
28+
expect(courses.sort(sort)).toEqual(expectedCourses.sort(sort));
29+
});
3230
});
3331
});
32+
33+
function sort(backofficeCourse1: BackofficeCourse, backofficeCourse2: BackofficeCourse): number {
34+
return backofficeCourse1?.id?.value.localeCompare(backofficeCourse2?.id?.value);
35+
}

tests/Contexts/Backoffice/Courses/infrastructure/MongoBackofficeCourseRepository.test.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,23 @@ afterAll(async () => {
1515
await (await environmentArranger).close();
1616
});
1717

18-
describe('Mongo BackofficeCourse Repository', () => {
19-
it('should return the existing courses', async () => {
20-
const courses = [BackofficeCourseMother.random(), BackofficeCourseMother.random()];
18+
describe('MongoBackofficeCourseRepository', () => {
19+
describe('#searchAll', () => {
20+
it('should return the existing courses', async () => {
21+
const courses = [BackofficeCourseMother.random(), BackofficeCourseMother.random()];
2122

22-
await Promise.all(courses.map(course => repository.save(course)));
23+
await Promise.all(courses.map(course => repository.save(course)));
2324

24-
const expectedCourses = await repository.searchAll();
25-
expect(courses.sort(sort)).toStrictEqual(expectedCourses.sort(sort));
26-
});
25+
const expectedCourses = await repository.searchAll();
26+
expect(courses.sort(sort)).toStrictEqual(expectedCourses.sort(sort));
27+
});
2728

28-
it('should save a course', async () => {
29-
const course = BackofficeCourseMother.random();
29+
it('should save a course', async () => {
30+
const course = BackofficeCourseMother.random();
3031

31-
await repository.save(course);
32-
expect(await repository.searchAll()).toContainEqual(course);
32+
await repository.save(course);
33+
expect(await repository.searchAll()).toContainEqual(course);
34+
});
3335
});
3436
});
3537

tests/Contexts/Mooc/Courses/application/CourseCreator.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ beforeEach(() => {
1616
handler = new CreateCourseCommandHandler(creator);
1717
});
1818

19-
it('should create a valid course', async () => {
20-
const command = CreateCourseCommandMother.random();
21-
await handler.handle(command);
19+
describe('CourseCreator', () => {
20+
it('should create a valid course', async () => {
21+
const command = CreateCourseCommandMother.random();
22+
await handler.handle(command);
2223

23-
const course = CourseMother.fromCommand(command);
24-
repository.assertLastSavedCourseIs(course);
24+
const course = CourseMother.fromCommand(command);
25+
repository.assertLastSavedCourseIs(course);
26+
});
2527
});

tests/Contexts/Mooc/Courses/infrastructure/persistence/CourseRepository.test.ts renamed to tests/Contexts/Mooc/Courses/infrastructure/persistence/MongoCourseRepository.test.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,26 @@ afterAll(async () => {
1414
await (await environmentArranger).close();
1515
});
1616

17-
describe('Save Course', () => {
18-
it('should save a course', async () => {
19-
const course = CourseMother.random();
17+
describe('MongoCourseRepository', () => {
18+
describe('#save', () => {
19+
it('should save a course', async () => {
20+
const course = CourseMother.random();
2021

21-
await repository.save(course);
22+
await repository.save(course);
23+
});
2224
});
23-
});
2425

25-
describe('Search Course', () => {
26-
it('should return an existing course', async () => {
27-
const course = CourseMother.random();
26+
describe('#search', () => {
27+
it('should return an existing course', async () => {
28+
const course = CourseMother.random();
2829

29-
await repository.save(course);
30+
await repository.save(course);
3031

31-
expect(course).toEqual(await repository.search(course.id));
32-
});
32+
expect(course).toEqual(await repository.search(course.id));
33+
});
3334

34-
it('should not return a non existing course', async () => {
35-
expect(await repository.search(CourseMother.random().id)).toBeFalsy();
35+
it('should not return a non existing course', async () => {
36+
expect(await repository.search(CourseMother.random().id)).toBeFalsy();
37+
});
3638
});
3739
});

tests/Contexts/Mooc/CoursesCounter/application/Find/FindCourseCounterQueryHandler.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { CoursesCounterFinder } from '../../../../../../src/Contexts/Mooc/CoursesCounter/application/Find/CoursesCounterFinder';
2+
import { FindCoursesCounterQuery } from '../../../../../../src/Contexts/Mooc/CoursesCounter/application/Find/FindCoursesCounterQuery';
3+
import { FindCoursesCounterQueryHandler } from '../../../../../../src/Contexts/Mooc/CoursesCounter/application/Find/FindCoursesCounterQueryHandler';
4+
import { CoursesCounterNotExist } from '../../../../../../src/Contexts/Mooc/CoursesCounter/domain/CoursesCounterNotExist';
25
import { CoursesCounterMother } from '../../domain/CoursesCounterMother';
3-
import { CoursesCounterRepositoryMock } from '../../__mocks__/CoursesCounterRepositoryMock';
46
import { CoursesCounterResponseMother } from '../../domain/CoursesCounterResponseMother';
5-
import { CoursesCounterNotExist } from '../../../../../../src/Contexts/Mooc/CoursesCounter/domain/CoursesCounterNotExist';
6-
import { FindCoursesCounterQueryHandler } from '../../../../../../src/Contexts/Mooc/CoursesCounter/application/Find/FindCoursesCounterQueryHandler';
7-
import { FindCoursesCounterQuery } from '../../../../../../src/Contexts/Mooc/CoursesCounter/application/Find/FindCoursesCounterQuery';
7+
import { CoursesCounterRepositoryMock } from '../../__mocks__/CoursesCounterRepositoryMock';
88

99
describe('FindCourseCounter QueryHandler', () => {
1010
let repository: CoursesCounterRepositoryMock;
@@ -13,16 +13,15 @@ describe('FindCourseCounter QueryHandler', () => {
1313
repository = new CoursesCounterRepositoryMock();
1414
});
1515

16-
1716
it('should find an existing courses counter', async () => {
1817
const counter = CoursesCounterMother.random();
1918
repository.returnOnSearch(counter);
2019

2120
const handler = new FindCoursesCounterQueryHandler(new CoursesCounterFinder(repository));
22-
21+
2322
const query = new FindCoursesCounterQuery();
2423
const response = await handler.handle(query);
25-
24+
2625
repository.assertSearch();
2726

2827
const expected = CoursesCounterResponseMother.create(counter.total);

tests/Contexts/Mooc/CoursesCounter/doubles/CoursesCounterRepository.ts

Whitespace-only changes.

tests/Contexts/Mooc/CoursesCounter/infrastructure/CoursesCounterRepository.test.ts renamed to tests/Contexts/Mooc/CoursesCounter/infrastructure/MongoCoursesCounterRepository.test.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,26 @@ afterAll(async () => {
1414
await (await environmentArranger).close();
1515
});
1616

17-
describe('Save CoursesCounter', () => {
18-
it('should save a courses counter', async () => {
19-
const course = CoursesCounterMother.random();
17+
describe('MongoCoursesCounterRepository', () => {
18+
describe('#save', () => {
19+
it('should save a courses counter', async () => {
20+
const course = CoursesCounterMother.random();
2021

21-
await repository.save(course);
22+
await repository.save(course);
23+
});
2224
});
23-
});
2425

25-
describe('Search CoursesCounter', () => {
26-
it('should return an existing course', async () => {
27-
const counter = CoursesCounterMother.random();
26+
describe('#search', () => {
27+
it('should return an existing course', async () => {
28+
const counter = CoursesCounterMother.random();
2829

29-
await repository.save(counter);
30+
await repository.save(counter);
3031

31-
expect(counter).toEqual(await repository.search());
32-
});
32+
expect(counter).toEqual(await repository.search());
33+
});
3334

34-
it('should not return null if there is no courses counter', async () => {
35-
expect(await repository.search()).toBeFalsy();
35+
it('should not return null if there is no courses counter', async () => {
36+
expect(await repository.search()).toBeFalsy();
37+
});
3638
});
3739
});

tests/Contexts/Mooc/Notifications/application/SendWelcomeUserEmail/SendWelcomeUserEmailOnUserRegistered.test.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,7 @@ describe('SendWelcomeUserEmailOnUserRegistered event handler', () => {
3232
const sendWelcomeUserEmailOnUserRegistered = new SendWelcomeUserEmailOnUserRegistered(sendWelcomeUserEmail);
3333

3434
const domainEvent = aDomainEventWithEmailAddress(anEmailAddress());
35-
let error;
36-
37-
try {
38-
await sendWelcomeUserEmailOnUserRegistered.on(domainEvent);
39-
} catch (e) {
40-
error = e;
41-
}
42-
43-
expect(error).toBeDefined();
44-
expect(error).toBeInstanceOf(WelcomeUserEmailError);
45-
expect(error.message).toBe(`Error sending WelcomeUser email to ${domainEvent.userEmailAddress}`);
35+
await expect(sendWelcomeUserEmailOnUserRegistered.on(domainEvent)).rejects.toBeInstanceOf(WelcomeUserEmailError);
4636
});
4737
});
4838

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
import { MongoClientFactory } from '../../../../src/Contexts/Shared/infrastructure/persistence/mongo/MongoClientFactory';
22
import { MongoClient } from 'mongodb';
33

4-
describe('Create a client', () => {
5-
const factory = MongoClientFactory;
6-
let client: MongoClient;
4+
describe('MongoClientFactory', () => {
5+
describe('#createClient', () => {
6+
const factory = MongoClientFactory;
7+
let client: MongoClient;
78

8-
beforeEach(async () => {
9-
client = await factory.createClient('test', { url: 'mongodb://localhost:27017/mooc-backend-test' });
10-
});
9+
beforeEach(async () => {
10+
client = await factory.createClient('test', { url: 'mongodb://localhost:27017/mooc-backend-test' });
11+
});
1112

12-
afterEach(async () => {
13-
await client.close();
14-
});
13+
afterEach(async () => {
14+
await client.close();
15+
});
1516

16-
it('creates a new client with the connection already established', () => {
17-
expect(client).toBeInstanceOf(MongoClient);
18-
expect(client.isConnected()).toBeTruthy();
19-
});
17+
it('creates a new client with the connection already established', () => {
18+
expect(client).toBeInstanceOf(MongoClient);
19+
expect(client.isConnected()).toBeTruthy();
20+
});
2021

21-
it('creates a new client if it does not exist a client with the given name', async () => {
22-
const newClient = await factory.createClient('test2', { url: 'mongodb://localhost:27017/mooc-backend-test' });
22+
it('creates a new client if it does not exist a client with the given name', async () => {
23+
const newClient = await factory.createClient('test2', { url: 'mongodb://localhost:27017/mooc-backend-test' });
2324

24-
expect(newClient).not.toBe(client);
25+
expect(newClient).not.toBe(client);
2526

26-
await newClient.close();
27-
});
27+
await newClient.close();
28+
});
2829

29-
it('returns a client if it already exists', async () => {
30-
const newClient = await factory.createClient('test', { url: 'mongodb://localhost:27017/mooc-backend-test' });
30+
it('returns a client if it already exists', async () => {
31+
const newClient = await factory.createClient('test', { url: 'mongodb://localhost:27017/mooc-backend-test' });
3132

32-
expect(newClient).toBe(client);
33+
expect(newClient).toBe(client);
3334

34-
await newClient.close();
35+
await newClient.close();
36+
});
3537
});
3638
});

0 commit comments

Comments
 (0)