-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6f9069
commit b1370cf
Showing
6 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@labdigital/commercetools-mock': minor | ||
--- | ||
|
||
Improve support for /me endpoint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import type { MyCustomerDraft } from '@commercetools/platform-sdk' | ||
import supertest from 'supertest' | ||
import { afterEach, describe, expect, test } from 'vitest' | ||
import { afterEach, beforeEach, describe, expect, test } from 'vitest' | ||
import { CommercetoolsMock } from '../index.js' | ||
|
||
const ctMock = new CommercetoolsMock() | ||
|
@@ -51,3 +51,58 @@ describe('Me', () => { | |
expect(response.body).toEqual(createResponse.body.customer) | ||
}) | ||
}) | ||
|
||
describe('/me', () => { | ||
afterEach(() => { | ||
ctMock.clear() | ||
}) | ||
|
||
beforeEach(() => { | ||
ctMock.project('dummy').add('customer', { | ||
id: '123', | ||
createdAt: '2021-03-18T14:00:00.000Z', | ||
version: 2, | ||
lastModifiedAt: '2021-03-18T14:00:00.000Z', | ||
email: '[email protected]', | ||
addresses: [], | ||
isEmailVerified: true, | ||
authenticationMode: 'password', | ||
custom: { type: { typeId: 'type', id: '' }, fields: {} }, | ||
}) | ||
}) | ||
|
||
test('Get me', async () => { | ||
const response = await supertest(ctMock.app).get('/dummy/me') | ||
|
||
expect(response.status).toBe(200) | ||
expect(response.body).toEqual({ | ||
id: '123', | ||
createdAt: '2021-03-18T14:00:00.000Z', | ||
version: 2, | ||
lastModifiedAt: '2021-03-18T14:00:00.000Z', | ||
email: '[email protected]', | ||
addresses: [], | ||
isEmailVerified: true, | ||
authenticationMode: 'password', | ||
custom: { | ||
fields: {}, | ||
type: { | ||
id: '', | ||
typeId: 'type', | ||
}, | ||
}, | ||
}) | ||
}) | ||
|
||
test('setCustomField', async () => { | ||
const response = await supertest(ctMock.app) | ||
.post(`/dummy/me`) | ||
.send({ | ||
version: 2, | ||
actions: [{ action: 'setCustomField', name: 'foobar', value: true }], | ||
}) | ||
expect(response.status).toBe(200) | ||
expect(response.body.version).toBe(3) | ||
expect(response.body.custom.fields.foobar).toBe(true) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Router } from 'express' | ||
import { ShoppingListRepository } from '../repositories/shopping-list.js' | ||
import AbstractService from './abstract.js' | ||
|
||
export class MyShoppingListService extends AbstractService { | ||
public repository: ShoppingListRepository | ||
|
||
constructor(parent: Router, repository: ShoppingListRepository) { | ||
super(parent) | ||
this.repository = repository | ||
} | ||
|
||
getBasePath() { | ||
return 'me/shopping-lists' | ||
} | ||
} |