From aa6895547fb9842f6eb6545d611d00d2c5334214 Mon Sep 17 00:00:00 2001 From: Erez Sobel Date: Mon, 17 Sep 2018 10:36:07 +0200 Subject: [PATCH] fix(products): fix typos -- pluralize to products --- src/errors.ts | 4 +- src/tillhub-js.ts | 10 +- src/v1/index.ts | 4 +- src/v1/product.ts | 99 ------------------- src/v1/products.ts | 18 ++-- .../create-product.test.ts | 8 +- 6 files changed, 22 insertions(+), 121 deletions(-) delete mode 100644 src/v1/product.ts rename test/{product => products}/create-product.test.ts (90%) diff --git a/src/errors.ts b/src/errors.ts index 5de6977c0f1..10647c35dca 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -34,8 +34,8 @@ export class TaxesFetchFailed extends BaseError { } } -export class ProductCreateFailed extends BaseError { - public name = 'ProductCreateFailed' +export class ProductsCreateFailed extends BaseError { + public name = 'ProductsCreateFailed' constructor(public message: string = 'Could not create the product') { super(message) } diff --git a/src/tillhub-js.ts b/src/tillhub-js.ts index 2f58fb39d41..0c749a0d56e 100644 --- a/src/tillhub-js.ts +++ b/src/tillhub-js.ts @@ -115,15 +115,15 @@ export class TillhubClient { } /** - * Create an authenticated products instance - * - */ - product(): v1.Product { + * Create an authenticated products instance + * + */ + products(): v1.Products { if (!this.options || !this.options.base || !this.http || !this.auth) { throw new errors.UninstantiatedClient() } - return new v1.Product({ user: this.auth.user, base: this.options.base }, this.http) + return new v1.Products({ user: this.auth.user, base: this.options.base }, this.http) } productGroups(): v0.ProductGroups { diff --git a/src/v1/index.ts b/src/v1/index.ts index b122df63a01..2e137872cd4 100644 --- a/src/v1/index.ts +++ b/src/v1/index.ts @@ -1,5 +1,5 @@ import { Auth } from './auth' -import { Product } from './product' +import { Products } from './products' import { Templates } from './templates' -export { Auth, Product, Templates } +export { Auth, Products, Templates } diff --git a/src/v1/product.ts b/src/v1/product.ts deleted file mode 100644 index a56d473d878..00000000000 --- a/src/v1/product.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { Client } from '../client' -import * as errors from '../errors' - -export interface Images { - '1x'?: string - avatar?: string -} - -type ProductTypes = - | 'product' - | 'voucher' - | 'linked' - | 'linked_product' - | 'variant' - | 'variant_product' - -export interface ProductType { - name?: string - description?: string | null - attributes?: object | null - parent?: string | null - tags?: any[] | null - linked_products?: any[] | null - prices?: object - barcode?: string | null - sku?: string | null - stock_minimum?: number | null - stock_maximum?: number | null - stockable?: boolean | null - metadata?: object | null - audiences?: any[] | null - keywords?: any[] | null - categories?: any[] | null - related_to?: any[] | null - similar_to?: any[] | null - released_at?: string | null - purchased_at?: string | null - produced_at?: string | null - custom_id?: string | null - tax?: string - taxes_options?: any[] | object | null - season?: string | null - seasons?: object | null - account?: string - vat_class?: string | null - category?: string | null - brand?: string | null - active?: boolean - deleted?: boolean - type?: ProductTypes - manufacturer?: object | null - supplier?: object | null - condition?: string | null - images?: Images | null - summary?: string | null - insert_id?: number - product_group?: string | null - delegated_to?: string[] | null -} - -export interface ProductOptions { - user?: string - base?: string -} - -export interface ProductResponse { - data: object[] - metadata: object -} - -export class Product { - endpoint: string - http: Client - public options: ProductOptions - - constructor(options: ProductOptions, http: Client) { - this.options = options - this.http = http - - this.endpoint = '/api/v1/products' - this.options.base = this.options.base || 'https://api.tillhub.com' - } - - createProduct(product: ProductType): Promise { - return new Promise(async (resolve, reject) => { - const uri = `${this.options.base}${this.endpoint}/${this.options.user}` - try { - const response = await this.http.getClient().post(uri, product) - - return resolve({ - data: response.data.results, - metadata: { count: response.data.count } - } as ProductResponse) - } catch (err) { - return reject(new errors.ProductCreateFailed()) - } - }) - } -} diff --git a/src/v1/products.ts b/src/v1/products.ts index a56d473d878..795aa2a3023 100644 --- a/src/v1/products.ts +++ b/src/v1/products.ts @@ -14,7 +14,7 @@ type ProductTypes = | 'variant' | 'variant_product' -export interface ProductType { +export interface Product { name?: string description?: string | null attributes?: object | null @@ -58,22 +58,22 @@ export interface ProductType { delegated_to?: string[] | null } -export interface ProductOptions { +export interface ProductsOptions { user?: string base?: string } -export interface ProductResponse { +export interface ProductsResponse { data: object[] metadata: object } -export class Product { +export class Products { endpoint: string http: Client - public options: ProductOptions + public options: ProductsOptions - constructor(options: ProductOptions, http: Client) { + constructor(options: ProductsOptions, http: Client) { this.options = options this.http = http @@ -81,7 +81,7 @@ export class Product { this.options.base = this.options.base || 'https://api.tillhub.com' } - createProduct(product: ProductType): Promise { + create(product: Product): Promise { return new Promise(async (resolve, reject) => { const uri = `${this.options.base}${this.endpoint}/${this.options.user}` try { @@ -90,9 +90,9 @@ export class Product { return resolve({ data: response.data.results, metadata: { count: response.data.count } - } as ProductResponse) + } as ProductsResponse) } catch (err) { - return reject(new errors.ProductCreateFailed()) + return reject(new errors.ProductsCreateFailed()) } }) } diff --git a/test/product/create-product.test.ts b/test/products/create-product.test.ts similarity index 90% rename from test/product/create-product.test.ts rename to test/products/create-product.test.ts index 52b560ed574..e98a7e00c91 100644 --- a/test/product/create-product.test.ts +++ b/test/products/create-product.test.ts @@ -22,7 +22,7 @@ const productObj = { name: 'iPhone' } -describe('Craete Product', () => { +describe('Create a new Product', () => { it('create', async () => { if (process.env.SYSTEM_TEST !== 'true') { const mock = new MockAdapter(axios) @@ -65,11 +65,11 @@ describe('Craete Product', () => { password: user.password }) - const product = th.product() + const products = th.products() - expect(product).toBeInstanceOf(v1.Product) + expect(products).toBeInstanceOf(v1.Products) - const { data } = await product.createProduct(productObj) + const { data } = await products.create(productObj) expect(data).toEqual(productObj) })