-
-
Notifications
You must be signed in to change notification settings - Fork 379
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
wip(mongo-sample): rearrange sample - add in-memory for e2e, mockingbird and dto's #1221
base: master
Are you sure you want to change the base?
Conversation
# Conflicts: # apps/mongo-sample/src/cat/service/cat.service.spec.ts
Lots of changes I'm seeing! Most of them good. Can we stay away from the |
Haha yes, a lot of changes. Thanks! And yes, sure, I will change the structure accordingly :) |
const moduleRef: TestingModule = await Test.createTestingModule({ | ||
imports: [AppModule], | ||
}) | ||
.overrideProvider(MongooseModuleConfigService) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmcdo29, what do you think about the in-memory
practice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it looks like it could work well. We should make sure to be explicit in that it is an in-memory mock. Maybe naming the file like cat.in-memory.e2e-spec.ts
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the name should not indicate the kind of mock/DB you're using in your test - but I can still change it if you like to.
Maybe add some comments at the beginning of the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only reason to mention the naming thing here is that this is a repo of samples, so I want people to be sure they know what they're looking at. Normally, I agree, the naming shouldn't matter so much, but as it's all example based, I'd like it to
const mockCat: ( | ||
name?: string, | ||
id?: string, | ||
age?: number, | ||
breed?: string, | ||
) => Cat = ( | ||
name = 'Ventus', | ||
id = 'a uuid', | ||
age = 4, | ||
breed = 'Russian Blue', | ||
): Cat => ({ | ||
name, | ||
id, | ||
age, | ||
breed, | ||
}); | ||
) => { | ||
return { | ||
name, | ||
id, | ||
age, | ||
breed, | ||
}; | ||
}; | ||
|
||
// still lazy, but this time using an object instead of multiple parameters | ||
const mockCatDoc = (mock?: Partial<Cat>): Partial<CatDoc> => ({ | ||
name: mock?.name || 'Ventus', | ||
_id: mock?.id || 'a uuid', | ||
age: mock?.age || 4, | ||
breed: mock?.breed || 'Russian Blue', | ||
}); | ||
const mockCatDoc: (mock?: { | ||
name?: string; | ||
id?: string; | ||
breed?: string; | ||
age?: number; | ||
}) => Partial<CatDocument> = (mock?: { | ||
name: string; | ||
id: string; | ||
age: number; | ||
breed: string; | ||
}) => { | ||
return { | ||
name: (mock && mock.name) || 'Ventus', | ||
_id: (mock && mock.id) || 'a uuid', | ||
age: (mock && mock.age) || 4, | ||
breed: (mock && mock.breed) || 'Russian Blue', | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we revert this change back to the shorter version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by 'shorter version'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const mockCatDoc = (mock?: Partial<Cat>): Partial<CatDoc> => ({
name: mock?.name || 'Ventus',
_id: mock?.id || 'a uuid',
age: mock?.age || 4,
breed: mock?.breed || 'Russian Blue',
});
Instead of
const mockCatDoc: (mock?: {
name?: string;
id?: string;
breed?: string;
age?: number;
}) => Partial<CatDocument> = (mock?: {
name: string;
id: string;
age: number;
breed: string;
}) => {
return {
name: (mock && mock.name) || 'Ventus',
_id: (mock && mock.id) || 'a uuid',
age: (mock && mock.age) || 4,
breed: (mock && mock.breed) || 'Russian Blue',
};
};
@@ -1,9 +1,9 @@ | |||
import { createMock } from '@golevelup/nestjs-testing'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this file back to mongo-sample/src/cat/cat.controller.spec.ts
@@ -8,9 +8,9 @@ import { | |||
Post, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this back to mongo-sample/src/cat/cat.controller.ts
@@ -0,0 +1,5 @@ | |||
import { Cat } from '../interfaces/cat.interface'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to mongo-sample/src/cat/cat.dto.ts
@@ -0,0 +1,17 @@ | |||
import { Document } from 'mongoose'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this back to mongo-sample/src/cat/cat.document.ts
@jmcdo29 I'm still working on the example, I had a rough week :/ |
Sure. Feel free to keep this open and work when you can or just close it out and create a new PR. |
I will keep this one open 🙏🏼 |
The purpose of this pull request is to put some order in the "cat" entity.
I reorganized the entities: interface, DTO and turned the Mongoose Schema into a class (using nestjs mongoose decorators).
Other than that I plan to add an e2e test containing a mongo-in-memory connection and use the Mockingbird library to create some fixtures.