@labdigital/commercetools-mock 1.6.1 → 1.7.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,10 +1,16 @@
1
- import type { Category } from '@commercetools/platform-sdk'
1
+ import type {
2
+ Category,
3
+ CategoryAddAssetAction,
4
+ CategoryRemoveAssetAction,
5
+ } from '@commercetools/platform-sdk'
2
6
  import supertest from 'supertest'
3
- import { beforeEach, describe, expect, test } from 'vitest'
7
+ import { beforeEach, afterEach, describe, expect, test } from 'vitest'
4
8
  import { CommercetoolsMock } from '../index.js'
9
+ import assert from 'assert'
5
10
 
6
11
  describe('Categories Query', () => {
7
12
  const ctMock = new CommercetoolsMock()
13
+ let category: Category | undefined
8
14
 
9
15
  beforeEach(async () => {
10
16
  const response = await supertest(ctMock.app)
@@ -19,6 +25,12 @@ describe('Categories Query', () => {
19
25
  orderHint: '0.1',
20
26
  })
21
27
  expect(response.status).toBe(201)
28
+
29
+ category = response.body as Category
30
+ })
31
+
32
+ afterEach(() => {
33
+ ctMock.clear()
22
34
  })
23
35
 
24
36
  test('no filter', async () => {
@@ -35,3 +47,106 @@ describe('Categories Query', () => {
35
47
  expect(category.name.en).toBe('Top hat')
36
48
  })
37
49
  })
50
+
51
+ describe('Categories add asset', () => {
52
+ const ctMock = new CommercetoolsMock()
53
+ let category: Category | undefined
54
+
55
+ beforeEach(async () => {
56
+ const response = await supertest(ctMock.app)
57
+ .post('/dummy/categories')
58
+ .send({
59
+ name: {
60
+ en: 'Top hat',
61
+ },
62
+ slug: {
63
+ en: 'top-hat',
64
+ },
65
+ orderHint: '0.1',
66
+ assets: [
67
+ {
68
+ key: 'some-key',
69
+ },
70
+ ],
71
+ })
72
+ expect(response.status).toBe(201)
73
+
74
+ category = response.body as Category
75
+ })
76
+
77
+ test('add second asset', async () => {
78
+ assert(category, 'category not created')
79
+
80
+ const response = await supertest(ctMock.app)
81
+ .post(`/dummy/categories/${category.id}`)
82
+ .send({
83
+ version: 1,
84
+ actions: [
85
+ {
86
+ action: 'addAsset',
87
+ asset: {
88
+ key: 'some-other-key',
89
+ },
90
+ } as CategoryAddAssetAction,
91
+ ],
92
+ })
93
+
94
+ expect(response.status).toBe(200)
95
+ expect(response.body.assets).toHaveLength(2)
96
+ expect(response.body.assets[0].key).toEqual('some-key')
97
+ expect(response.body.assets[1].key).toEqual('some-other-key')
98
+ })
99
+ })
100
+
101
+ describe('Categories remove asset', () => {
102
+ const ctMock = new CommercetoolsMock()
103
+ let category: Category | undefined
104
+
105
+ beforeEach(async () => {
106
+ const response = await supertest(ctMock.app)
107
+ .post('/dummy/categories')
108
+ .send({
109
+ name: {
110
+ en: 'Top hat',
111
+ },
112
+ slug: {
113
+ en: 'top-hat',
114
+ },
115
+ orderHint: '0.1',
116
+ assets: [
117
+ {
118
+ key: 'some-key',
119
+ },
120
+ {
121
+ key: 'some-other-key',
122
+ },
123
+ ],
124
+ })
125
+ expect(response.status).toBe(201)
126
+
127
+ category = response.body as Category
128
+ })
129
+
130
+ test('remove assets by id and key', async () => {
131
+ assert(category, 'category not created')
132
+
133
+ const response = await supertest(ctMock.app)
134
+ .post(`/dummy/categories/${category.id}`)
135
+ .send({
136
+ version: 1,
137
+ actions: [
138
+ {
139
+ action: 'removeAsset',
140
+ assetKey: category.assets[1].key,
141
+ } as CategoryRemoveAssetAction,
142
+ {
143
+ action: 'removeAsset',
144
+ assetId: category.assets[0].id,
145
+ } as CategoryRemoveAssetAction,
146
+ ],
147
+ })
148
+
149
+ expect(response.status).toBe(200)
150
+ expect(response.body.assets).toHaveLength(0)
151
+ })
152
+ })
@@ -1,3 +1,4 @@
1
+ import { AssociateRoleServices } from './associate-roles'
1
2
  import { CartService } from './cart.js'
2
3
  import { CartDiscountService } from './cart-discount.js'
3
4
  import { CategoryServices } from './category.js'
@@ -30,6 +31,7 @@ import { ZoneService } from './zone.js'
30
31
  import { AttributeGroupService } from './attribute-group.js'
31
32
 
32
33
  export const createServices = (router: any, repos: any) => ({
34
+ 'associate-role': new AssociateRoleServices(router, repos['associate-role']),
33
35
  category: new CategoryServices(router, repos['category']),
34
36
  cart: new CartService(router, repos['cart'], repos['order']),
35
37
  'cart-discount': new CartDiscountService(router, repos['cart-discount']),