-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client|redux): expose closet endpoints
This exposes user closet endpoints
- Loading branch information
1 parent
130f915
commit 56e4a05
Showing
59 changed files
with
2,189 additions
and
12 deletions.
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
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
16 changes: 16 additions & 0 deletions
16
packages/client/src/users/closets/__fixtures__/deleteUserClosetItem.fixtures.ts
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 { rest, type RestHandler } from 'msw'; | ||
|
||
const path = '/api/account/v1/users/:userId/closets/:closetId/items/:itemId'; | ||
|
||
const fixtures = { | ||
success: (response: number): RestHandler => | ||
rest.delete(path, (_req, res, ctx) => | ||
res(ctx.status(200), ctx.json(response)), | ||
), | ||
failure: (): RestHandler => | ||
rest.delete(path, (_req, res, ctx) => | ||
res(ctx.status(404), ctx.json({ message: 'stub error' })), | ||
), | ||
}; | ||
|
||
export default fixtures; |
17 changes: 17 additions & 0 deletions
17
packages/client/src/users/closets/__fixtures__/getUserClosetItems.fixtures.ts
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,17 @@ | ||
import { rest, type RestHandler } from 'msw'; | ||
import type { ClosetItems } from '../index.js'; | ||
|
||
const path = '/api/account/v1/users/:userId/closets/:closetId/items'; | ||
|
||
const fixtures = { | ||
success: (response: ClosetItems): RestHandler => | ||
rest.get(path, (_req, res, ctx) => | ||
res(ctx.status(200), ctx.json(response)), | ||
), | ||
failure: (): RestHandler => | ||
rest.get(path, (_req, res, ctx) => | ||
res(ctx.status(404), ctx.json({ message: 'stub error' })), | ||
), | ||
}; | ||
|
||
export default fixtures; |
17 changes: 17 additions & 0 deletions
17
packages/client/src/users/closets/__fixtures__/getUserClosets.fixtures.ts
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,17 @@ | ||
import { rest, type RestHandler } from 'msw'; | ||
import type { Closet } from '../index.js'; | ||
|
||
const path = '/api/account/v1/users/:userId/closets'; | ||
|
||
const fixtures = { | ||
success: (response: Closet[]): RestHandler => | ||
rest.get(path, (_req, res, ctx) => | ||
res(ctx.status(200), ctx.json(response)), | ||
), | ||
failure: (): RestHandler => | ||
rest.get(path, (_req, res, ctx) => | ||
res(ctx.status(404), ctx.json({ message: 'stub error' })), | ||
), | ||
}; | ||
|
||
export default fixtures; |
11 changes: 11 additions & 0 deletions
11
packages/client/src/users/closets/__tests__/__snapshots__/deleteUserClosetItem.test.ts.snap
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,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`deleteUserClosetItem should receive a client request error 1`] = ` | ||
Object { | ||
"code": "-1", | ||
"message": "stub error", | ||
"name": "AxiosError", | ||
"status": 404, | ||
"transportLayerErrorCode": "ERR_BAD_REQUEST", | ||
} | ||
`; |
11 changes: 11 additions & 0 deletions
11
packages/client/src/users/closets/__tests__/__snapshots__/getUserClosetItems.test.ts.snap
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,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`getUserClosetItems should receive a client request error 1`] = ` | ||
Object { | ||
"code": "-1", | ||
"message": "stub error", | ||
"name": "AxiosError", | ||
"status": 404, | ||
"transportLayerErrorCode": "ERR_BAD_REQUEST", | ||
} | ||
`; |
11 changes: 11 additions & 0 deletions
11
packages/client/src/users/closets/__tests__/__snapshots__/getUserClosets.test.ts.snap
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,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`getUserClosets should receive a client request error 1`] = ` | ||
Object { | ||
"code": "-1", | ||
"message": "stub error", | ||
"name": "AxiosError", | ||
"status": 404, | ||
"transportLayerErrorCode": "ERR_BAD_REQUEST", | ||
} | ||
`; |
44 changes: 44 additions & 0 deletions
44
packages/client/src/users/closets/__tests__/deleteUserClosetItem.test.ts
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,44 @@ | ||
import { | ||
closetId, | ||
closetItemId, | ||
userId, | ||
} from 'tests/__fixtures__/users/index.mjs'; | ||
import { deleteUserClosetItem } from '../index.js'; | ||
import client from '../../../helpers/client/index.js'; | ||
import fixtures from '../__fixtures__/deleteUserClosetItem.fixtures.js'; | ||
import mswServer from '../../../../tests/mswServer.js'; | ||
|
||
describe('deleteUserClosetItem', () => { | ||
const expectedConfig = undefined; | ||
const spy = jest.spyOn(client, 'delete'); | ||
|
||
beforeEach(() => jest.clearAllMocks()); | ||
|
||
it('should handle a client request successfully', async () => { | ||
const response = 200; | ||
|
||
mswServer.use(fixtures.success(response)); | ||
|
||
await expect( | ||
deleteUserClosetItem(userId, closetId, closetItemId), | ||
).resolves.toBe(response); | ||
|
||
expect(spy).toHaveBeenCalledWith( | ||
`/account/v1/users/${userId}/closets/${closetId}/items/${closetItemId}`, | ||
expectedConfig, | ||
); | ||
}); | ||
|
||
it('should receive a client request error', async () => { | ||
mswServer.use(fixtures.failure()); | ||
|
||
await expect( | ||
deleteUserClosetItem(userId, closetId, closetItemId), | ||
).rejects.toMatchSnapshot(); | ||
|
||
expect(spy).toHaveBeenCalledWith( | ||
`/account/v1/users/${userId}/closets/${closetId}/items/${closetItemId}`, | ||
expectedConfig, | ||
); | ||
}); | ||
}); |
42 changes: 42 additions & 0 deletions
42
packages/client/src/users/closets/__tests__/getUserClosetItems.test.ts
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,42 @@ | ||
import { | ||
closetId, | ||
mockGetUserClosetItemsResponse, | ||
userId, | ||
} from 'tests/__fixtures__/users/index.mjs'; | ||
import { getUserClosetItems } from '../index.js'; | ||
import client from '../../../helpers/client/index.js'; | ||
import fixtures from '../__fixtures__/getUserClosetItems.fixtures.js'; | ||
import mswServer from '../../../../tests/mswServer.js'; | ||
|
||
describe('getUserClosetItems', () => { | ||
const expectedConfig = undefined; | ||
const spy = jest.spyOn(client, 'get'); | ||
|
||
beforeEach(() => jest.clearAllMocks()); | ||
|
||
it('should handle a client request successfully', async () => { | ||
mswServer.use(fixtures.success(mockGetUserClosetItemsResponse)); | ||
|
||
await expect(getUserClosetItems(userId, closetId)).resolves.toStrictEqual( | ||
mockGetUserClosetItemsResponse, | ||
); | ||
|
||
expect(spy).toHaveBeenCalledWith( | ||
`/account/v1/users/${userId}/closets/${closetId}/items`, | ||
expectedConfig, | ||
); | ||
}); | ||
|
||
it('should receive a client request error', async () => { | ||
mswServer.use(fixtures.failure()); | ||
|
||
await expect( | ||
getUserClosetItems(userId, closetId), | ||
).rejects.toMatchSnapshot(); | ||
|
||
expect(spy).toHaveBeenCalledWith( | ||
`/account/v1/users/${userId}/closets/${closetId}/items`, | ||
expectedConfig, | ||
); | ||
}); | ||
}); |
39 changes: 39 additions & 0 deletions
39
packages/client/src/users/closets/__tests__/getUserClosets.test.ts
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,39 @@ | ||
import { getUserClosets } from '../index.js'; | ||
import { | ||
mockGetUserClosetsResponse, | ||
userId, | ||
} from 'tests/__fixtures__/users/index.mjs'; | ||
import client from '../../../helpers/client/index.js'; | ||
import fixtures from '../__fixtures__/getUserClosets.fixtures.js'; | ||
import mswServer from '../../../../tests/mswServer.js'; | ||
|
||
describe('getUserClosets', () => { | ||
const expectedConfig = undefined; | ||
const spy = jest.spyOn(client, 'get'); | ||
|
||
beforeEach(() => jest.clearAllMocks()); | ||
|
||
it('should handle a client request successfully', async () => { | ||
mswServer.use(fixtures.success(mockGetUserClosetsResponse)); | ||
|
||
await expect(getUserClosets(userId)).resolves.toStrictEqual( | ||
mockGetUserClosetsResponse, | ||
); | ||
|
||
expect(spy).toHaveBeenCalledWith( | ||
`/account/v1/users/${userId}/closets`, | ||
expectedConfig, | ||
); | ||
}); | ||
|
||
it('should receive a client request error', async () => { | ||
mswServer.use(fixtures.failure()); | ||
|
||
await expect(getUserClosets(userId)).rejects.toMatchSnapshot(); | ||
|
||
expect(spy).toHaveBeenCalledWith( | ||
`/account/v1/users/${userId}/closets`, | ||
expectedConfig, | ||
); | ||
}); | ||
}); |
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,39 @@ | ||
import { adaptError } from '../../helpers/client/formatError.js'; | ||
import client from '../../helpers/client/index.js'; | ||
import join from 'proper-url-join'; | ||
import type { DeleteUserClosetItem } from './types/index.js'; | ||
|
||
/** | ||
* Method responsible for deleting a user closet. | ||
* | ||
* @param userId - Universal identifier of the user. | ||
* @param closetId - Closet identifier. | ||
* @param itemId - Closet item identifier. | ||
* @param config - Custom configurations to send to the client instance (axios). | ||
* | ||
* @returns Promise that will resolve when the call to the endpoint finishes. | ||
*/ | ||
const deleteUserClosetItem: DeleteUserClosetItem = ( | ||
userId, | ||
closetId, | ||
itemId, | ||
config, | ||
) => | ||
client | ||
.delete( | ||
join( | ||
'/account/v1/users', | ||
userId, | ||
'/closets/', | ||
closetId, | ||
'/items/', | ||
itemId, | ||
), | ||
config, | ||
) | ||
.then(response => response.status) | ||
.catch(error => { | ||
throw adaptError(error); | ||
}); | ||
|
||
export default deleteUserClosetItem; |
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,34 @@ | ||
import { adaptError } from '../../helpers/client/formatError.js'; | ||
import client from '../../helpers/client/index.js'; | ||
import join from 'proper-url-join'; | ||
import type { GetUserClosetItems } from './types/index.js'; | ||
|
||
/** | ||
* Method responsible for getting the items (paginated) from a specific closet. | ||
* | ||
* @param userId - Universal identifier of the user. | ||
* @param closetId - Closet identifier. | ||
* @param query - Query params. | ||
* @param config - Custom configurations to send to the client instance (axios). | ||
* | ||
* @returns Promise that will resolve when the call to the endpoint finishes. | ||
*/ | ||
const getUserClosetItems: GetUserClosetItems = ( | ||
userId, | ||
closetId, | ||
query, | ||
config, | ||
) => | ||
client | ||
.get( | ||
join('/account/v1/users/', userId, '/closets/', closetId, '/items', { | ||
query, | ||
}), | ||
config, | ||
) | ||
.then(response => response.data) | ||
.catch(error => { | ||
throw adaptError(error); | ||
}); | ||
|
||
export default getUserClosetItems; |
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,22 @@ | ||
import { adaptError } from '../../helpers/client/formatError.js'; | ||
import client from '../../helpers/client/index.js'; | ||
import join from 'proper-url-join'; | ||
import type { GetUserClosets } from './types/index.js'; | ||
|
||
/** | ||
* Method responsible for getting user closets. | ||
* | ||
* @param userId - Universal identifier of the user. | ||
* @param config - Custom configurations to send to the client instance (axios). | ||
* | ||
* @returns Promise that will resolve when the call to the endpoint finishes. | ||
*/ | ||
const getUserClosets: GetUserClosets = (userId, config) => | ||
client | ||
.get(join('/account/v1/users/', userId, '/closets'), config) | ||
.then(response => response.data) | ||
.catch(error => { | ||
throw adaptError(error); | ||
}); | ||
|
||
export default getUserClosets; |
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,4 @@ | ||
export { default as deleteUserClosetItem } from './deleteUserClosetItem.js'; | ||
export { default as getUserClosetItems } from './getUserClosetItems.js'; | ||
export { default as getUserClosets } from './getUserClosets.js'; | ||
export * from './types/index.js'; |
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 @@ | ||
export type Closet = { | ||
id: string; | ||
createdDate: string; | ||
totalItems: number; | ||
}; |
31 changes: 31 additions & 0 deletions
31
packages/client/src/users/closets/types/closetItem.types.ts
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,31 @@ | ||
import type { Brand } from '../../../brands/index.js'; | ||
import type { | ||
Color, | ||
PagedResponse, | ||
ProductImageGroup, | ||
ProductVariantAttribute, | ||
} from '../../../types/index.js'; | ||
import type { Order } from '../../../orders/index.js'; | ||
import type { Price, Product } from '../../../products/index.js'; | ||
import type { ProductCategory } from '../../../categories/index.js'; | ||
|
||
export type ClosetItems = PagedResponse<ClosetItem>; | ||
|
||
export type ClosetItem = { | ||
id: string; | ||
orderId: Order['id']; | ||
merchantId: number; | ||
productId: Product['result']['id']; | ||
productName: string; | ||
productDescription: string; | ||
attributes: ProductVariantAttribute[]; | ||
images: ProductImageGroup; | ||
categories: ProductCategory[]; | ||
colors: Color[]; | ||
price: Price; | ||
purchasePrice: Price; | ||
brand: Brand; | ||
customAttributes: string; | ||
isAvailable: boolean; | ||
createdDate: string; | ||
}; |
11 changes: 11 additions & 0 deletions
11
packages/client/src/users/closets/types/deleteUserClosetItem.types.ts
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,11 @@ | ||
import type { Closet } from './closet.types.js'; | ||
import type { ClosetItem } from './closetItem.types.js'; | ||
import type { Config } from '../../../types/index.js'; | ||
import type { User } from '../../authentication/types/user.types.js'; | ||
|
||
export type DeleteUserClosetItem = ( | ||
userId: User['id'], | ||
closetId: Closet['id'], | ||
itemId: ClosetItem['id'], | ||
config?: Config, | ||
) => Promise<number>; |
Oops, something went wrong.