Skip to content

Commit eccc4bc

Browse files
committed
PRO-10170 fix: replace reqres.in with dummyjson.com
1 parent 6692550 commit eccc4bc

22 files changed

Lines changed: 279 additions & 106 deletions

File tree

.eslintrc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ rules:
193193
'@typescript-eslint/no-loop-func': error
194194
'@typescript-eslint/no-magic-numbers':
195195
- error
196-
- ignore: [-2, -1, 0, 1, 2, 1024]
196+
- ignore: [-2, -1, 0, 1, 2, 1000, 1024]
197197
ignoreArrayIndexes: true
198198
ignoreDefaultValues: true
199199
ignoreEnums: true

autotests/entities/device.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const createDevice = async ({
1616
cookies,
1717
input: 7,
1818
model,
19+
title: model,
1920
version,
2021
});
2122

autotests/entities/product.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import type {ClientFunction} from 'e2ed/types';
88
*/
99
export const addProduct: ClientFunction<[Product], Promise<ApiProduct>> = createClientFunction(
1010
(product: Product) =>
11-
fetch(`https://reqres.in/api/product/${product.id}?size=${product.size}`, {
11+
fetch(`https://dummyjson.com/products/add?id=${product.id}&size=${product.size}`, {
1212
body: JSON.stringify({
1313
cookies: [],
1414
input: product.input,
1515
model: product.model,
16+
title: product.model,
1617
version: product.version,
1718
}),
18-
headers: {'Content-Type': 'application/json; charset=UTF-8', 'x-api-key': 'reqres-free-v1'},
19+
headers: {'Content-Type': 'application/json; charset=UTF-8'},
1920
method: 'POST',
2021
}).then((res) => res.json() as Promise<ApiProduct>),
2122
{name: 'addProduct', timeout: 2_000},

autotests/entities/worker.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,24 @@ let clientGetUsersRetries: number | undefined;
1212
/**
1313
* Adds user-worker.
1414
*/
15-
export const addUser: ClientFunction<[UserWorker, number?], Promise<object>> = createClientFunction(
16-
(user: UserWorker, delay?: number) =>
17-
fetch(`https://reqres.in/api/users${delay !== undefined ? `?delay=${delay}` : ''}`, {
15+
export const addUser: ClientFunction<
16+
[Readonly<{delay?: number; user: UserWorker}>],
17+
Promise<object>
18+
> = createClientFunction(
19+
({delay, user}) =>
20+
fetch(`https://dummyjson.com/users/add${delay !== undefined ? `?delay=${delay}` : ''}`, {
1821
body: JSON.stringify(user),
19-
headers: {
20-
'Content-Type': 'application/json; charset=UTF-8',
21-
...(delay !== undefined && delay > 0 ? {'x-api-key': 'reqres-free-v1'} : undefined),
22-
},
22+
headers: {'Content-Type': 'application/json; charset=UTF-8'},
2323
method: 'POST',
24-
}),
24+
})
25+
.then((res) => res.json())
26+
.then((result: UserWorker) => {
27+
// eslint-disable-next-line no-console
28+
console.log('addUser return', result);
29+
30+
return result;
31+
}),
32+
2533
{name: 'addUser', timeout: 3_000},
2634
);
2735

@@ -36,7 +44,7 @@ export const getUsers = ({delay = 0, retries = 0}: GetUsersOptions = {}): Promis
3644

3745
clientGetUsers = createClientFunction(
3846
(clientDelay: number) =>
39-
fetch(`https://reqres.in/api/users?delay=${clientDelay}`, {method: 'GET'}).then(
47+
fetch(`https://dummyjson.com/users?delay=${clientDelay}`, {method: 'GET'}).then(
4048
(res) => res.json() as unknown,
4149
),
4250
{name: 'getUsers', retries, timeout: 6_000},

autotests/pageObjects/pages/Main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export class Main extends Page<CustomPageParams> {
6868
({url}) => {
6969
if (
7070
url.startsWith('https://img-s-msn-com.akamaized.net/') ||
71+
url.startsWith('https://rewards.bing.com/widget/') ||
7172
url.startsWith('https://www.bing.com/th?id=')
7273
) {
7374
return false;

autotests/routes/apiRoutes/AddUser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {Url} from 'e2ed/types';
66

77
type Params = Readonly<{delay?: number}>;
88

9-
const pathStart = '/api/users';
9+
const pathStart = '/users/add';
1010

1111
/**
1212
* Client API route for adding user-worker.
@@ -37,7 +37,7 @@ export class AddUser extends ApiRoute<Params, ApiAddUserRequest, ApiAddUserRespo
3737
}
3838

3939
override getOrigin(): Url {
40-
return 'https://reqres.in' as Url;
40+
return 'https://dummyjson.com' as Url;
4141
}
4242

4343
getPath(): string {

autotests/routes/apiRoutes/CreateProduct.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {Url} from 'e2ed/types';
88

99
type Params = Readonly<{id: ProductId; size: number}>;
1010

11-
const pathStart = '/api/product/';
11+
const pathStart = '/products/add';
1212

1313
/**
1414
* Test API route for creating a product.
@@ -27,7 +27,7 @@ export class CreateProduct extends ApiRoute<
2727
{urlObject},
2828
);
2929

30-
const id = Number(urlObject.pathname.slice(pathStart.length)) as ProductId;
30+
const id = Number(urlObject.searchParams.get('id')) as ProductId;
3131
const size = Number(urlObject.searchParams.get('size'));
3232

3333
assertValueIsTrue(Number.isInteger(id), 'url has correct id', {id, size, urlObject});
@@ -43,6 +43,6 @@ export class CreateProduct extends ApiRoute<
4343
getPath(): string {
4444
const {id, size} = this.routeParams;
4545

46-
return `${pathStart}${id}?size=${size}`;
46+
return `${pathStart}?id=${id}&size=${size}`;
4747
}
4848
}

autotests/routes/apiRoutes/GetUsers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {Url} from 'e2ed/types';
66

77
type Params = Readonly<{delay?: number}> | undefined;
88

9-
const pathStart = '/api/users';
9+
const pathStart = '/users';
1010

1111
/**
1212
* Client API route for getting users list.
@@ -37,7 +37,7 @@ export class GetUsers extends ApiRoute<Params, ApiGetUsersRequest, ApiGetUsersRe
3737
}
3838

3939
override getOrigin(): Url {
40-
return 'https://reqres.in' as Url;
40+
return 'https://dummyjson.com' as Url;
4141
}
4242

4343
getPath(): string {

autotests/tests/e2edReportExample/fullMocks.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test('full mocks works correctly', {enableCsp: false, meta: {testId: '18'}}, asy
3535

3636
const mockedProduct = await addProduct(product);
3737

38-
const fetchUrl = `https://reqres.in/api/product/${productId}?size=${product.size}` as Url;
38+
const fetchUrl = `https://dummyjson.com/products/add?id=${productId}&size=${product.size}` as Url;
3939

4040
await expect(mockedProduct, 'mocked API returns correct result').eql({
4141
id: productId,
@@ -46,15 +46,19 @@ test('full mocks works correctly', {enableCsp: false, meta: {testId: '18'}}, asy
4646
id: String(productId) as DeviceId,
4747
input: product.input,
4848
model: product.model,
49+
title: product.model,
4950
version: product.version,
5051
},
51-
query: {size: product.size},
52+
query: {id: String(productId), size: product.size},
5253
url: fetchUrl,
5354
});
5455

5556
await unmockApiRoute(CreateProductRoute);
5657

5758
const newMockedProduct = await addProduct(product);
5859

59-
await expect('createdAt' in newMockedProduct, 'API mock on CreateProductRoute was umocked').ok();
60+
await expect(
61+
'title' in newMockedProduct && newMockedProduct.title === product.model,
62+
'API mock on CreateProductRoute was umocked',
63+
).ok();
6064
});

autotests/tests/internalTypeTests/waitForEvents.skip.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ void waitForRequestToRoute(AddUser, () => {}, {skipLogs: true});
9393
// ok
9494
void waitForRequestToRoute(AddUser, {
9595
predicate: ({delay}, {requestBody, url}) => {
96-
if (delay !== undefined && delay > 0 && requestBody.job !== 'foo') {
96+
if (delay !== undefined && delay > 0 && requestBody.firstName !== 'foo') {
9797
return url.startsWith('https');
9898
}
9999

100100
return false;
101101
},
102102
}).then(
103103
({request, routeParams}) =>
104-
request.requestBody.job === 'foo' && 'delay' in routeParams && routeParams.delay > 0,
104+
request.requestBody.lastName === 'foo' && 'delay' in routeParams && routeParams.delay > 0,
105105
);
106106

107107
// @ts-expect-error: waitForRequestToRoute does not accept routes without `getParamsFromUrlOrThrow` method
@@ -122,8 +122,8 @@ void waitForResponseToRoute(AddUser, {
122122
if (
123123
delay !== undefined &&
124124
delay > 0 &&
125-
requestBody.job !== 'foo' &&
126-
responseBody.job !== 'bar'
125+
requestBody.firstName !== 'foo' &&
126+
responseBody.firstName !== 'bar'
127127
) {
128128
return url.startsWith('https');
129129
}
@@ -132,8 +132,8 @@ void waitForResponseToRoute(AddUser, {
132132
},
133133
}).then(
134134
({response, routeParams}) =>
135-
response.request.requestBody.job === 'foo' &&
136-
response.responseBody.name === 'bar' &&
135+
response.request.requestBody.firstName === 'foo' &&
136+
response.responseBody.lastName === 'bar' &&
137137
'delay' in routeParams &&
138138
routeParams.delay > 0,
139139
);

0 commit comments

Comments
 (0)