-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ts] implement product.descriptions.get()
- Loading branch information
Showing
9 changed files
with
174 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[ | ||
{ | ||
"scope": "https://product-api.rozetka.com.ua:443", | ||
"method": "GET", | ||
"path": "/v4/goods/get-goods-description?front-type=xl&country=UA&lang=ru&goodsId=999999999&", | ||
"body": "", | ||
"status": 200, | ||
"response": [ | ||
"1f8b0800000000000003ab564a492c4954b2aa562a49ad2851b2ca2bcdc9d151ca28c9cd81b1338b83329333fcf27d327333810ad212738a5375948a80621015b53a4ac5a5c9c9a9c5c54a562545a5a9b500248acd9953000000" | ||
], | ||
"rawHeaders": [ | ||
"Server", | ||
"nginx", | ||
"Date", | ||
"Sun, 10 Apr 2022 02:03:24 GMT", | ||
"Content-Type", | ||
"application/json; charset=UTF-8", | ||
"Transfer-Encoding", | ||
"chunked", | ||
"Connection", | ||
"close", | ||
"domain", | ||
"product-api", | ||
"Content-Encoding", | ||
"gzip", | ||
"domain", | ||
"product-api" | ||
], | ||
"responseIsBinary": false | ||
} | ||
] |
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 @@ | ||
[ | ||
{ | ||
"scope": "https://product-api.rozetka.com.ua:443", | ||
"method": "GET", | ||
"path": "/v4/goods/get-goods-description?front-type=xl&country=UA&lang=ru&goodsId=6802844&", | ||
"body": "", | ||
"status": 200, | ||
"response": [ | ||
"1f8b08000000000000036d53cb6ed35010fd95e1ae4d23106c22cb3b7688057f9086a05a4a4b553b08a9aa64c714a85ade7bbec135b57af3727e61e617f812ce8ced48882c92dc79cf396772ee5e8dd2911b9ebb74f22e7543179e46844f78183d7b1b8f4ec2c161447fb29f249f65ce0d8db9e43597f295d8f33d575c4b8ec0a6755584a0978c6b7bc05dc328792537bb146ef88ecb03e25fea22180ddfca350225b2e768872c8d48ceb50dc86036bc56c7925778a22dc97bebbc910f52f0bd85bc5c127fb361db4097b18c4557a053515d23519b712373e2dff8c96ca34697f7c45bb3d7722d9f2c7b63c391d7875ad82831e09542090720ec34e21f044f2d1fadcceb92b9a5d66dbd0e59e9d3cc474f1fea0023afee0714303dfd437e3b562e6d4baf4babc3776b6fc0dc0264601c7083becc84e99121aca46c7b98a0056cdb06a55ca9224071439d8a7507c950a3f15a09f94fc73ea0d25ced6af42c3c54fd0e50a58104df9241ccf672406911ec41e64dfecc88b003205e1abedc1cedc442be10686d9d104e0ad36affd6a0a330fe97bbcb6b54895bd35f4f26efe8d3adfb9abd38175ad774ab54079dce0011c6a67601664b3ba80adf353d7e4200031151bbd28b7c100ee248c16aa90bdc517a3c75c393d9741ab83879198f8f5ebc791e1fc7f8e7bd1e4d9349e0cee06b332e0297ccc6e34992b8617a369b5cfc05ec27ff2fac030000" | ||
], | ||
"rawHeaders": [ | ||
"Server", | ||
"nginx", | ||
"Date", | ||
"Sun, 10 Apr 2022 02:03:24 GMT", | ||
"Content-Type", | ||
"application/json; charset=UTF-8", | ||
"Transfer-Encoding", | ||
"chunked", | ||
"Connection", | ||
"close", | ||
"domain", | ||
"product-api", | ||
"Content-Encoding", | ||
"gzip", | ||
"domain", | ||
"product-api" | ||
], | ||
"responseIsBinary": false | ||
} | ||
] |
22 changes: 22 additions & 0 deletions
22
source/products/descriptions/__snapshots__/test.integration.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,22 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`/products/descriptions GET When asked for an existing product | ||
Then should be able to retrieve and parse its description 1`] = ` | ||
Object { | ||
"html": null, | ||
"isRichNoLimit": false, | ||
"rich": null, | ||
"text": "<p> <p><b>Evian</b> – это cамая известная в мире минеральная вода. Она добывается на северном склоне французских Альп, в районе далеком от городов и промышленного производства. </p><p>В течение своего долгого 15-летнего пути <b>Evian</b> проходит природный фильтр из горных пород, обогащаясь естественными минеральными веществами. Благодаря этому, <b>Evian</b> приобретает кристальную чистоту и естественный уникально сбалансированный минеральный состав.</p><p><b><i>В упаковке 24 бутылки!</i></b></p>", | ||
} | ||
`; | ||
|
||
exports[`/products/descriptions GET When asked for an non-existing product | ||
Then should return an Error object 1`] = ` | ||
[ZodError: [ | ||
{ | ||
"code": "custom", | ||
"message": "Bad response. The item you have requested is not available.", | ||
"path": [] | ||
} | ||
]] | ||
`; |
22 changes: 22 additions & 0 deletions
22
source/products/descriptions/__snapshots__/test.unit.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,22 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`/products/descriptions GET When asked for an existing product | ||
Then should be able to retrieve and parse its description 1`] = ` | ||
Object { | ||
"html": null, | ||
"isRichNoLimit": false, | ||
"rich": null, | ||
"text": "<p> <p><b>Evian</b> – это cамая известная в мире минеральная вода. Она добывается на северном склоне французских Альп, в районе далеком от городов и промышленного производства. </p><p>В течение своего долгого 15-летнего пути <b>Evian</b> проходит природный фильтр из горных пород, обогащаясь естественными минеральными веществами. Благодаря этому, <b>Evian</b> приобретает кристальную чистоту и естественный уникально сбалансированный минеральный состав.</p><p><b><i>В упаковке 24 бутылки!</i></b></p>", | ||
} | ||
`; | ||
|
||
exports[`/products/descriptions GET When asked for an non-existing product | ||
Then should return an Error object 1`] = ` | ||
[ZodError: [ | ||
{ | ||
"code": "custom", | ||
"message": "Bad response. The item you have requested is not available.", | ||
"path": [] | ||
} | ||
]] | ||
`; |
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,9 @@ | ||
import { product } from '../../client/index' | ||
import type { Either } from '../../types/either' | ||
import { genericParams } from '../genericParams' | ||
import { Description } from './types' | ||
|
||
export const get = (productId: number): Promise<Either<Description>> => | ||
product | ||
.get('v4/goods/get-goods-description', genericParams(productId)) | ||
.then((r) => Description.safeParse(r)) |
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,20 @@ | ||
import { PRODUCT_ID, WRONG_PRODUCT_ID } from '../fixtures' | ||
import { get } from './index' | ||
|
||
describe('/products/descriptions', () => { | ||
describe('GET', () => { | ||
it('When asked for an existing product \n\t Then should be able to retrieve and parse its description', async () => { | ||
expect.assertions(1) | ||
|
||
const r = await get(PRODUCT_ID) | ||
expect(r.data).toMatchSnapshot() | ||
}) | ||
it('When asked for an non-existing product \n\t Then should return an Error object', async () => { | ||
expect.assertions(2) | ||
|
||
const r = await get(WRONG_PRODUCT_ID) | ||
expect(r.error).toBeInstanceOf(Error) | ||
expect(r.error).toMatchSnapshot() | ||
}) | ||
}) | ||
}) |
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,25 @@ | ||
import { server } from '../../utils/mockServer' | ||
import { PRODUCT_ID, WRONG_PRODUCT_ID } from '../fixtures' | ||
import { get } from './index' | ||
|
||
describe('/products/descriptions', () => { | ||
describe('GET', () => { | ||
it('When asked for an existing product \n\t Then should be able to retrieve and parse its description', async () => { | ||
expect.assertions(1) | ||
const { done } = await server(import.meta.url, 'good.json') | ||
|
||
const r = await get(PRODUCT_ID) | ||
expect(r.data).toMatchSnapshot() | ||
done() | ||
}) | ||
it('When asked for an non-existing product \n\t Then should return an Error object', async () => { | ||
expect.assertions(2) | ||
const { done } = await server(import.meta.url, 'empty.json') | ||
|
||
const r = await get(WRONG_PRODUCT_ID) | ||
expect(r.error).toBeInstanceOf(Error) | ||
expect(r.error).toMatchSnapshot() | ||
done() | ||
}) | ||
}) | ||
}) |
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,14 @@ | ||
import { z } from 'zod' | ||
import { customError } from '../../types/error' | ||
|
||
export const Description = z | ||
.object({ | ||
text: z.string().nullable(), | ||
html: z.string().nullable(), | ||
isRichNoLimit: z.boolean(), | ||
rich: z.string().nullable() | ||
}) | ||
.refine((o) => Object.values(o).some((v) => v), customError('empty_response')) | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-redeclare | ||
export type Description = z.infer<typeof Description> |
This file was deleted.
Oops, something went wrong.