Skip to content

Commit

Permalink
fix(catalog): fix mandatory fields in interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
gdostie committed Sep 23, 2019
1 parent 1a00187 commit 8bd363d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/resources/Catalogs/Catalog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import API from '../../APICore';
import {PageModel} from '../BaseInterfaces';
import {CatalogModel, CatalogsListOptions} from './Interfaces';
import {CatalogModel, CatalogsListOptions, NewCatalogModel} from './Interfaces';

export default class Catalog {
static baseUrl = `/rest/organizations/${API.orgPlaceholder}/catalogs`;
Expand All @@ -11,7 +11,7 @@ export default class Catalog {
return this.api.get<PageModel<CatalogModel>>(Catalog.baseUrl, options);
}

create(catalog: CatalogModel) {
create(catalog: NewCatalogModel) {
return this.api.post<CatalogModel>(Catalog.baseUrl, catalog);
}

Expand Down
12 changes: 7 additions & 5 deletions src/resources/Catalogs/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@ export interface CatalogsListOptions {
}

export interface CatalogModel {
id: string;
name: string;
product: ProductHierarchyModel;
availability?: AvailabilityHierarchyModel;
description?: string;
id?: string;
name?: string;
product?: ProductHierarchyModel;
variant?: VariantHierarchyModel;
}

export type NewCatalogModel = Omit<CatalogModel, 'id'>;

export interface VariantHierarchyModel {
fields: string[];
idField: string;
objectType: string;
}

export interface ProductHierarchyModel {
idField?: string;
objectType?: string;
idField: string;
objectType: string;
}

export interface AvailabilityHierarchyModel {
Expand Down
12 changes: 10 additions & 2 deletions src/resources/Catalogs/tests/Catalog.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import API from '../../../APICore';
import Catalog from '../Catalog';
import {CatalogModel, CatalogsListOptions} from '../Interfaces';
import {CatalogModel, CatalogsListOptions, NewCatalogModel} from '../Interfaces';

jest.mock('../../../APICore');

Expand Down Expand Up @@ -29,8 +29,12 @@ describe('Catalog', () => {

describe('create', () => {
it('should make a POST call to the catalogs base url', () => {
const catalogModel: CatalogModel = {
const catalogModel: NewCatalogModel = {
name: 'New catalog',
product: {
idField: '@uri',
objectType: 'product',
},
};

catalog.create(catalogModel);
Expand Down Expand Up @@ -62,6 +66,10 @@ describe('Catalog', () => {
const catalogModel: CatalogModel = {
id: 'catalog-to-update-id',
name: 'Catalog to be updated',
product: {
idField: '@uri',
objectType: 'product',
},
};

catalog.update(catalogModel);
Expand Down

0 comments on commit 8bd363d

Please sign in to comment.