Skip to content

Commit fabc6d0

Browse files
mikedebockmvantellingen
authored andcommitted
fix getByKey with expand when resource not found
1 parent f45b6c7 commit fabc6d0

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/services/product-projection.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ describe('Product Projection', () => {
5656
})
5757
})
5858

59+
test('Get product projection by 404 when not found by key with expand', async () => {
60+
const response = await supertest(ctMock.app).get(
61+
'/dummy/product-projections/key=DOESNOTEXIST?' +
62+
qs.stringify({
63+
expand: ['categories[*]'],
64+
})
65+
)
66+
67+
expect(response.status).toBe(404)
68+
})
69+
5970
test('Search product projection', async () => {
6071
ctMock.project('dummy').add('product-projection', {
6172
id: '',

src/storage.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,14 @@ export class InMemoryStorage extends AbstractStorage {
211211

212212
const resources: any[] = Array.from(store.values())
213213
const resource = resources.find(e => e.key === key)
214-
if (params.expand) return this.expand(projectKey, resource, params.expand)
215-
return resource
214+
if (resource) {
215+
return this.expand(
216+
projectKey,
217+
resource,
218+
params.expand
219+
) as ResourceMap[RepositoryTypes]
220+
}
221+
return null
216222
}
217223

218224
delete(

0 commit comments

Comments
 (0)