-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from coveo/ADUI-4773/unit-tests-hackaton-files
Improve test coverage
- Loading branch information
Showing
10 changed files
with
311 additions
and
94 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface PageModel<T> { | ||
items: T[]; | ||
totalEntries: number; | ||
totalPages: number; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export interface CatalogsListOptions { | ||
page?: number; | ||
pageSize?: number; | ||
} | ||
|
||
export interface CatalogModel { | ||
id: string; | ||
name: string; | ||
product: ProductHierarchyModel; | ||
availability?: AvailabilityHierarchyModel; | ||
description?: string; | ||
variant?: VariantHierarchyModel; | ||
} | ||
|
||
export type NewCatalogModel = Omit<CatalogModel, 'id'>; | ||
|
||
export interface VariantHierarchyModel { | ||
fields: string[]; | ||
idField: string; | ||
objectType: string; | ||
} | ||
|
||
export interface ProductHierarchyModel { | ||
idField: string; | ||
objectType: string; | ||
} | ||
|
||
export interface AvailabilityHierarchyModel { | ||
availableSkusField: string; | ||
fields: string[]; | ||
objectType: 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,80 @@ | ||
import API from '../../../APICore'; | ||
import Catalog from '../Catalog'; | ||
import {CatalogModel, CatalogsListOptions, NewCatalogModel} from '../Interfaces'; | ||
|
||
jest.mock('../../../APICore'); | ||
|
||
const APIMock: jest.Mock<API> = API as any; | ||
|
||
describe('Catalog', () => { | ||
let catalog: Catalog; | ||
const api = new APIMock() as jest.Mocked<API>; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
catalog = new Catalog(api); | ||
}); | ||
|
||
describe('list', () => { | ||
it('should make a GET call to the catalogs base url', () => { | ||
const options: CatalogsListOptions = { | ||
page: 2, | ||
pageSize: 10, | ||
}; | ||
catalog.list(options); | ||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(Catalog.baseUrl, options); | ||
}); | ||
}); | ||
|
||
describe('create', () => { | ||
it('should make a POST call to the catalogs base url', () => { | ||
const catalogModel: NewCatalogModel = { | ||
name: 'New catalog', | ||
product: { | ||
idField: '@uri', | ||
objectType: 'product', | ||
}, | ||
}; | ||
|
||
catalog.create(catalogModel); | ||
expect(api.post).toHaveBeenCalledTimes(1); | ||
expect(api.post).toHaveBeenCalledWith(Catalog.baseUrl, catalogModel); | ||
}); | ||
}); | ||
|
||
describe('delete', () => { | ||
it('should make a DELETE call to the specific catalog url', () => { | ||
const catalogToDeleteId = 'catalog-to-be-deleted'; | ||
catalog.delete(catalogToDeleteId); | ||
expect(api.delete).toHaveBeenCalledTimes(1); | ||
expect(api.delete).toHaveBeenCalledWith(`${Catalog.baseUrl}/${catalogToDeleteId}`); | ||
}); | ||
}); | ||
|
||
describe('get', () => { | ||
it('should make a GET call to the specific catalog url', () => { | ||
const catalogToGetId = 'catalog-to-be-fetched'; | ||
catalog.get(catalogToGetId); | ||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(`${Catalog.baseUrl}/${catalogToGetId}`); | ||
}); | ||
}); | ||
|
||
describe('update', () => { | ||
it('should make a PUT call to the specific catalog url', () => { | ||
const catalogModel: CatalogModel = { | ||
id: 'catalog-to-update-id', | ||
name: 'Catalog to be updated', | ||
product: { | ||
idField: '@uri', | ||
objectType: 'product', | ||
}, | ||
}; | ||
|
||
catalog.update(catalogModel); | ||
expect(api.put).toHaveBeenCalledTimes(1); | ||
expect(api.put).toHaveBeenCalledWith(`${Catalog.baseUrl}/${catalogModel.id}`, catalogModel); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import API from '../../APICore'; | ||
import CoveoPlatform from '../../CoveoPlatform'; | ||
import Catalog from '../Catalogs/Catalog'; | ||
import {Resources} from '../Resources'; | ||
|
||
describe('Resources', () => { | ||
describe('registerAll', () => { | ||
let platform: CoveoPlatform; | ||
let api: API; | ||
|
||
beforeEach(() => { | ||
platform = {} as CoveoPlatform; | ||
api = {} as API; | ||
}); | ||
|
||
it('should register the catalog resource on the platform instance', () => { | ||
Resources.registerAll(platform, api); | ||
|
||
expect(platform.catalog).toBeDefined(); | ||
expect(platform.catalog).toBeInstanceOf(Catalog); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.