-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
102 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
import {Reaction, ReactionTypeEnum} from "src/model/blog/types"; | ||
import {Document, model, Model, Schema} from "mongoose"; | ||
import {Reaction, ReactionTypeEnum} from "src/blog/types"; | ||
|
||
export const reactionCollection = 'blogReactions'; | ||
export type ReactionModel = Reaction & Document; | ||
export type ReactionModel = Reaction & Document & {active?: boolean}; | ||
|
||
export type IReactionRepo = Model<ReactionModel>; | ||
|
||
const schema = new Schema<ReactionModel>({ | ||
type: {type: ReactionTypeEnum, required: true}, | ||
idArticle: {type: String, required: true}, | ||
idUser: {type: String, required: true} | ||
idUser: {type: String, required: true}, | ||
active: {type: Boolean, required: true, default: true} | ||
}); | ||
|
||
|
||
|
||
export const ReactionRepo = | ||
model<ReactionModel>(reactionCollection, schema, reactionCollection); | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
export enum ReactionTypeEnum{ | ||
like, | ||
dislike | ||
dislike, | ||
} | ||
|
||
export interface Reaction { | ||
type: ReactionTypeEnum, | ||
idArticle: string | ||
idUser: string | ||
idArticle: string, | ||
idUser: string, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import {successPromise} from "src/tests/utilsTest"; | ||
import {Reaction, ReactionTypeEnum} from "src/blog/types"; | ||
import {active, BlogApp} from "src/blog/BlogApp"; | ||
import {IReactionRepo, ReactionModel} from "src/blog/ReactionRepo"; | ||
|
||
const fakeReaction: Reaction = { | ||
type: ReactionTypeEnum.dislike, | ||
idArticle: "Fake id article", | ||
idUser: "48597" | ||
}; | ||
|
||
describe('Blog app', () => { | ||
const getTarget = (repo: any) => | ||
new BlogApp(repo as IReactionRepo); | ||
|
||
test('Insert Reaction', async () => { | ||
// given | ||
const create = jest.fn() | ||
.mockImplementationOnce(() => | ||
new Promise<ReactionModel>((resolve) => resolve(fakeReaction as ReactionModel))); | ||
|
||
const target = getTarget({create}); | ||
// when | ||
const action = () => target.createReaction(fakeReaction); | ||
|
||
// then | ||
await expect(action()).resolves; | ||
expect(create).toBeCalledWith(fakeReaction); | ||
}); | ||
|
||
test('list reactions', async () => { | ||
|
||
const listFakeReaction = [{ | ||
...fakeReaction, | ||
_id: "this shouldn't show to controller" | ||
}]; | ||
const expected = { | ||
idUser: fakeReaction.idUser, | ||
active | ||
}; | ||
|
||
const find = jest.fn() | ||
.mockImplementationOnce(() => | ||
new Promise<ReactionModel[]>(resolve => resolve(listFakeReaction as ReactionModel[]))); | ||
|
||
const target = getTarget({find}); | ||
|
||
const result = await target.listReactionsByUser(fakeReaction.idUser); | ||
|
||
expect(result).toEqual([fakeReaction]); | ||
expect(find).toBeCalledWith(expected); | ||
}); | ||
|
||
test('delete reaction', async () => { | ||
const findOneAndUpdate = jest.fn() | ||
.mockImplementationOnce(successPromise); | ||
|
||
const target = getTarget({findOneAndUpdate}); | ||
|
||
const action = () => target.deleteReaction(fakeReaction.idUser, fakeReaction.idArticle); | ||
|
||
await expect(action()).resolves; | ||
expect(findOneAndUpdate).toBeCalledWith(fakeReaction, {active: false}); | ||
}) | ||
}); |
9 changes: 5 additions & 4 deletions
9
src/tests/controllers/BlogController.test.ts → src/tests/blog/BlogController.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
src/tests/model/user/UserApp.test.ts → src/tests/user/UserApp.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/tests/controllers/UserController.test.ts → src/tests/user/UserController.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.