Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(products): fix typos -- pluralize to products
  • Loading branch information
erezsob committed Sep 17, 2018
1 parent 5150935 commit aa68955
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 121 deletions.
4 changes: 2 additions & 2 deletions src/errors.ts
Expand Up @@ -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)
}
Expand Down
10 changes: 5 additions & 5 deletions src/tillhub-js.ts
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions 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 }
99 changes: 0 additions & 99 deletions src/v1/product.ts

This file was deleted.

18 changes: 9 additions & 9 deletions src/v1/products.ts
Expand Up @@ -14,7 +14,7 @@ type ProductTypes =
| 'variant'
| 'variant_product'

export interface ProductType {
export interface Product {
name?: string
description?: string | null
attributes?: object | null
Expand Down Expand Up @@ -58,30 +58,30 @@ 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

this.endpoint = '/api/v1/products'
this.options.base = this.options.base || 'https://api.tillhub.com'
}

createProduct(product: ProductType): Promise<ProductResponse> {
create(product: Product): Promise<ProductsResponse> {
return new Promise(async (resolve, reject) => {
const uri = `${this.options.base}${this.endpoint}/${this.options.user}`
try {
Expand All @@ -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())
}
})
}
Expand Down
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
})
Expand Down

0 comments on commit aa68955

Please sign in to comment.