@labdigital/commercetools-mock 1.6.0 → 1.6.2

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
+ })
@@ -199,26 +199,36 @@ afterEach(async () => {
199
199
  timekeeper.reset()
200
200
  ctMock.clear()
201
201
  })
202
+ // Test the general product projection implementation
203
+ describe('Product Projection Get By ID', () => {
204
+ test('Get By ID', async () => {
205
+ const response = await supertest(ctMock.app).get(
206
+ `/dummy/product-projections/${publishedProduct.id}`
207
+ )
208
+
209
+ const result: ProductProjection = response.body
210
+ expect(result).toBeDefined()
211
+ expect(result.id).toBe(publishedProduct.id)
212
+ })
213
+ })
202
214
 
203
215
  // Test the general product projection implementation
204
216
  describe('Product Projection Query - Generic', () => {
205
217
  test('Filter out staged', async () => {
206
- {
207
- const response = await supertest(ctMock.app)
208
- .get('/dummy/product-projections')
209
- .query({
210
- limit: 50,
211
- })
212
-
213
- const result: ProductProjectionPagedSearchResponse = response.body
214
- expect(result).toEqual({
215
- count: 1,
218
+ const response = await supertest(ctMock.app)
219
+ .get('/dummy/product-projections')
220
+ .query({
216
221
  limit: 50,
217
- offset: 0,
218
- total: 1,
219
- results: [productProjection],
220
222
  })
221
- }
223
+
224
+ const result: ProductProjectionPagedSearchResponse = response.body
225
+ expect(result).toEqual({
226
+ count: 1,
227
+ limit: 50,
228
+ offset: 0,
229
+ total: 1,
230
+ results: [productProjection],
231
+ })
222
232
  })
223
233
 
224
234
  test('Filter on valid slug', async () => {