Skip to content

Commit

Permalink
adding support for standalone price
Browse files Browse the repository at this point in the history
  • Loading branch information
bala-goflink authored and mvantellingen committed Mar 10, 2023
1 parent 73a7bc6 commit d81b817
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ProductProjectionService } from './product-projection'
import { ProductTypeService } from './product-type'
import { ShippingMethodService } from './shipping-method'
import { ShoppingListService } from './shopping-list'
import { StandAlonePriceService } from './standalone-price'
import { StateService } from './state'
import { StoreService } from './store'
import { SubscriptionService } from './subscription'
Expand All @@ -46,6 +47,7 @@ export const createServices = (router: any, repos: any) => ({
),
order: new OrderService(router, repos['order']),
payment: new PaymentService(router, repos['payment']),
'standalone-price': new StandAlonePriceService(router, repos['standalone-price']),
'my-cart': new MyCartService(router, repos['my-cart']),
'my-order': new MyOrderService(router, repos['my-order']),
'my-customer': new MyCustomerService(router, repos['my-customer']),
Expand Down
37 changes: 37 additions & 0 deletions src/services/standalone-price.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { StandalonePriceDraft } from '@commercetools/platform-sdk'
import supertest from 'supertest'
import { CommercetoolsMock } from '../index'

const ctMock = new CommercetoolsMock()

describe('StandalonePrice', () => {
test('Create standalone price', async () => {
const draft: StandalonePriceDraft = {
sku: 'test-sku',
value: {
currencyCode: 'EUR',
centAmount: 1000,
},
active: true,
}

const response = await supertest(ctMock.app).post('/dummy/standalone-prices').send(draft)
expect(response.status).toBe(201)
})

test('Get standalone price', async () => {
const draft: StandalonePriceDraft = {
sku: 'test-sku',
value: {
currencyCode: 'EUR',
centAmount: 1000,
},
active: true,
}

const createResponse = await supertest(ctMock.app).post('/dummy/standalone-prices').send(draft)

const response = await supertest(ctMock.app).get(`/dummy/standalone-prices/${createResponse.body.id}`)
expect(response.status).toBe(200)
})
})
16 changes: 16 additions & 0 deletions src/services/standalone-price.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Router } from 'express'
import { StandAlonePriceRepository } from '../repositories/standalone-price'
import AbstractService from './abstract'

export class StandAlonePriceService extends AbstractService {
public repository: StandAlonePriceRepository

constructor(parent: Router, repository: StandAlonePriceRepository) {
super(parent)
this.repository = repository
}

getBasePath() {
return 'standalone-prices'
}
}

0 comments on commit d81b817

Please sign in to comment.