@labdigital/commercetools-mock 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
- import { AssociateRoleServices } from './associate-roles'
1
+ import { AssociateRoleServices } from './associate-roles.js'
2
+ import { BusinessUnitServices } from './business-units.js'
2
3
  import { CartService } from './cart.js'
3
4
  import { CartDiscountService } from './cart-discount.js'
4
5
  import { CategoryServices } from './category.js'
@@ -32,6 +33,7 @@ import { AttributeGroupService } from './attribute-group.js'
32
33
 
33
34
  export const createServices = (router: any, repos: any) => ({
34
35
  'associate-role': new AssociateRoleServices(router, repos['associate-role']),
36
+ 'business-unit': new BusinessUnitServices(router, repos['business-unit']),
35
37
  category: new CategoryServices(router, repos['category']),
36
38
  cart: new CartService(router, repos['cart'], repos['order']),
37
39
  'cart-discount': new CartDiscountService(router, repos['cart-discount']),
@@ -1,7 +1,11 @@
1
1
  import { Request, Response, Router } from 'express'
2
2
  import { getRepositoryContext } from '../repositories/helpers.js'
3
- import { ProductProjectionRepository } from './../repositories/product-projection.js'
3
+ import {
4
+ ProductProjectionQueryParams,
5
+ ProductProjectionRepository,
6
+ } from './../repositories/product-projection.js'
4
7
  import AbstractService from './abstract.js'
8
+ import { queryParamsArray, queryParamsValue } from '../helpers.js'
5
9
 
6
10
  export class ProductProjectionService extends AbstractService {
7
11
  public repository: ProductProjectionRepository
@@ -34,9 +38,25 @@ export class ProductProjectionService extends AbstractService {
34
38
  }
35
39
 
36
40
  search(request: Request, response: Response) {
41
+ const query = request.query
42
+ const searchParams: ProductProjectionQueryParams = {
43
+ filter: queryParamsArray(query.filter),
44
+ 'filter.query': queryParamsArray(query['filter.query']),
45
+ facet: queryParamsArray(query.facet),
46
+ expand: queryParamsArray(query.expand),
47
+ staged: queryParamsValue(query.staged) === 'true',
48
+ localeProjection: queryParamsValue(query.localeProjection),
49
+ storeProjection: queryParamsValue(query.storeProjection),
50
+ priceChannel: queryParamsValue(query.priceChannel),
51
+ priceCountry: queryParamsValue(query.priceCountry),
52
+ priceCurrency: queryParamsValue(query.priceCurrency),
53
+ priceCustomerGroup: queryParamsValue(query.priceCustomerGroup),
54
+ offset: query.offset ? Number(queryParamsValue(query.offset)) : undefined,
55
+ limit: query.limit ? Number(queryParamsValue(query.limit)) : undefined,
56
+ }
37
57
  const resource = this.repository.search(
38
58
  getRepositoryContext(request),
39
- request.query
59
+ searchParams
40
60
  )
41
61
  return response.status(200).send(resource)
42
62
  }
@@ -0,0 +1,52 @@
1
+ import type { Project } from '@commercetools/platform-sdk'
2
+ import supertest from 'supertest'
3
+ import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest'
4
+ import { CommercetoolsMock } from '../index.js'
5
+
6
+ const ctMock = new CommercetoolsMock()
7
+
8
+ describe('Project', () => {
9
+ beforeAll(() => {
10
+ ctMock.start()
11
+ })
12
+
13
+ afterEach(() => {
14
+ ctMock.clear()
15
+ })
16
+
17
+ afterAll(() => {
18
+ ctMock.stop()
19
+ })
20
+
21
+ test('Get project by key', async () => {
22
+ const response = await supertest(ctMock.app).get('/dummy/')
23
+
24
+ expect(response.status).toBe(200)
25
+ expect(response.body).toEqual({
26
+ version: 1,
27
+ carts: {
28
+ countryTaxRateFallbackEnabled: false,
29
+ deleteDaysAfterLastModification: 90,
30
+ },
31
+ countries: [],
32
+ createdAt: '2018-10-04T11:32:12.603Z',
33
+ currencies: [],
34
+ key: 'dummy',
35
+ languages: [],
36
+ messages: {
37
+ deleteDaysAfterCreation: 15,
38
+ enabled: false,
39
+ },
40
+ name: '',
41
+ searchIndexing: {
42
+ orders: {
43
+ status: 'Deactivated',
44
+ },
45
+ products: {
46
+ status: 'Deactivated',
47
+ },
48
+ },
49
+ trialUntil: '2018-12',
50
+ } as Project)
51
+ })
52
+ })