-
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
1 parent
027a606
commit d63133b
Showing
4 changed files
with
374 additions
and
4 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
28 changes: 28 additions & 0 deletions
28
test/domain/use-cases/instrument_model/get-one-instrument_model.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { InstrumentModelRepository } from "../../../../src/domain/interfaces/repositories/instrument_model-repository"; | ||
import { MockInstrumentModelRepository } from "../../../mocks/instrumentModel-mock"; | ||
import { GetOneInstrumentModel } from '../../../../src/domain/use-cases/instrument_model/get-one-instrument_model'; | ||
import { instrument_model_response } from "../../../entities/instrumentModel"; | ||
|
||
|
||
let mockInstrumentModelRepository: InstrumentModelRepository; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockInstrumentModelRepository = new MockInstrumentModelRepository() | ||
}) | ||
|
||
describe("Domain - Use Cases - Get One Instrument Model", () => { | ||
test("Get one instrument model by id : Ok ", async () => { | ||
const getOneInstrumentModelUseCase = new GetOneInstrumentModel(mockInstrumentModelRepository) | ||
jest.spyOn(mockInstrumentModelRepository, 'getOneInstrumentModel').mockResolvedValueOnce(instrument_model_response); | ||
|
||
const instrumentModel = await getOneInstrumentModelUseCase.execute(1); | ||
expect(instrumentModel.instrument_model_id).toBe(1); | ||
}); | ||
test("Get one instrument model by id : Not found ", async () => { | ||
const getOneInstrumentModelUseCase = new GetOneInstrumentModel(mockInstrumentModelRepository) | ||
jest.spyOn(mockInstrumentModelRepository, 'getOneInstrumentModel').mockResolvedValueOnce(null); | ||
await expect(getOneInstrumentModelUseCase.execute(2)).rejects.toThrow("Cannot find instrument_model"); | ||
|
||
}); | ||
}); |
57 changes: 57 additions & 0 deletions
57
test/domain/use-cases/instrument_model/search-instrument_model.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { InstrumentModelRepository } from "../../../../src/domain/interfaces/repositories/instrument_model-repository"; | ||
import { MockInstrumentModelRepository } from "../../../mocks/instrumentModel-mock"; | ||
import { MockSearchRepository } from "../../../mocks/search-mock"; | ||
import { SearchInstrumentModels } from '../../../../src/domain/use-cases/instrument_model/search-instrument_model'; | ||
import { instrument_model_response } from "../../../entities/instrumentModel"; | ||
import { SearchRepository } from "../../../../src/domain/interfaces/repositories/search-repository"; | ||
|
||
|
||
let mockInstrumentModelRepository: InstrumentModelRepository; | ||
let mockSearchRepository: SearchRepository; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockInstrumentModelRepository = new MockInstrumentModelRepository() | ||
mockSearchRepository = new MockSearchRepository() | ||
}) | ||
|
||
describe("Domain - Use Cases - Search Instrument Models", () => { | ||
test("Search instrument models with filters, should be forced to empty ", async () => { | ||
const options = { filter: [{ field: "instrument_model_name", operator: "=", value: "UVP5" }], sort_by: [], page: 1, limit: 10 } | ||
const instruments = { items: [instrument_model_response], total: 1 } | ||
const search_info_response = { total: 1, page: 1, pages: 1, limit: 10, total_on_page: 1 } | ||
|
||
jest.spyOn(mockSearchRepository, 'formatSortBy').mockReturnValueOnce([]); | ||
jest.spyOn(mockInstrumentModelRepository, 'standardGetInstrumentModels').mockResolvedValueOnce(instruments); | ||
jest.spyOn(mockSearchRepository, 'formatSearchInfo').mockReturnValueOnce(search_info_response); | ||
|
||
|
||
const searchInstrumentModelsUseCase = new SearchInstrumentModels(mockInstrumentModelRepository, mockSearchRepository) | ||
const { instrument_models, search_info } = await searchInstrumentModelsUseCase.execute(options); | ||
|
||
expect(instrument_models.length).toBe(1); | ||
expect(search_info.total).toBe(1); | ||
expect(mockSearchRepository.formatSortBy).toHaveBeenCalledWith([]); | ||
expect(mockInstrumentModelRepository.standardGetInstrumentModels).toHaveBeenCalledWith({ filter: [], sort_by: [], page: 1, limit: 10 }); | ||
expect(mockSearchRepository.formatSearchInfo).toHaveBeenCalledWith(instruments, options); | ||
}); | ||
test("Throw error when searching instrument models", async () => { | ||
const options = { filter: [{ field: "instrument_model_name", operator: "=", value: "UVP5" }], sort_by: [], page: 1, limit: 10 } | ||
const search_info_response = { total: 1, page: 1, pages: 1, limit: 10, total_on_page: 1 } | ||
|
||
jest.spyOn(mockSearchRepository, 'formatSortBy').mockReturnValueOnce([]); | ||
jest.spyOn(mockInstrumentModelRepository, 'standardGetInstrumentModels').mockRejectedValueOnce(new Error()); | ||
jest.spyOn(mockSearchRepository, 'formatSearchInfo').mockReturnValueOnce(search_info_response); | ||
|
||
try { | ||
const searchInstrumentModelsUseCase = new SearchInstrumentModels(mockInstrumentModelRepository, mockSearchRepository) | ||
await searchInstrumentModelsUseCase.execute(options); | ||
} catch (error) { | ||
expect(error.message).toBe("Cannot search instrument models"); | ||
|
||
expect(mockSearchRepository.formatSortBy).toHaveBeenCalledWith([]); | ||
expect(mockInstrumentModelRepository.standardGetInstrumentModels).toHaveBeenCalledWith({ filter: [], sort_by: [], page: 1, limit: 10 }); | ||
expect(mockSearchRepository.formatSearchInfo).not.toHaveBeenCalled(); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.