@opra/testing 0.0.9 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/expect/api-expect-fail.js +15 -0
- package/cjs/expect/api-expect-list.js +104 -6
- package/cjs/expect/{api-expect-resource.js → api-expect-object.js} +4 -4
- package/cjs/expect/api-expect.js +24 -19
- package/cjs/testers/base-operation-tester.js +16 -0
- package/cjs/testers/entity-create-tester.js +16 -16
- package/cjs/testers/entity-delete-many-tester.js +23 -0
- package/cjs/testers/entity-delete-tester.js +22 -0
- package/cjs/testers/entity-get-tester.js +17 -17
- package/cjs/testers/entity-search-tester.js +75 -0
- package/cjs/testers/entity-tester.js +46 -2
- package/cjs/testers/entity-update-many-tester.js +27 -0
- package/cjs/testers/entity-update-tester.js +44 -0
- package/esm/expect/api-expect-fail.d.ts +6 -0
- package/esm/expect/api-expect-fail.js +11 -0
- package/esm/expect/api-expect-list.d.ts +9 -2
- package/esm/expect/api-expect-list.js +101 -5
- package/esm/expect/{api-expect-resource.d.ts → api-expect-object.d.ts} +2 -2
- package/esm/expect/{api-expect-resource.js → api-expect-object.js} +2 -2
- package/esm/expect/api-expect.d.ts +6 -9
- package/esm/expect/api-expect.js +24 -19
- package/esm/testers/base-operation-tester.d.ts +12 -0
- package/esm/testers/base-operation-tester.js +12 -0
- package/esm/testers/base-tester.d.ts +1 -1
- package/esm/testers/entity-create-tester.d.ts +3 -3
- package/esm/testers/entity-create-tester.js +16 -16
- package/esm/testers/entity-delete-many-tester.d.ts +12 -0
- package/esm/testers/entity-delete-many-tester.js +18 -0
- package/esm/testers/entity-delete-tester.d.ts +14 -0
- package/esm/testers/entity-delete-tester.js +17 -0
- package/esm/testers/entity-get-tester.d.ts +3 -3
- package/esm/testers/entity-get-tester.js +17 -17
- package/esm/testers/entity-search-tester.d.ts +22 -0
- package/esm/testers/entity-search-tester.js +70 -0
- package/esm/testers/entity-tester.d.ts +12 -2
- package/esm/testers/entity-tester.js +46 -2
- package/esm/testers/entity-update-many-tester.d.ts +14 -0
- package/esm/testers/entity-update-many-tester.js +22 -0
- package/esm/testers/entity-update-tester.d.ts +19 -0
- package/esm/testers/entity-update-tester.js +39 -0
- package/package.json +4 -3
- package/cjs/expect/api-expect-errors.js +0 -17
- package/esm/expect/api-expect-errors.d.ts +0 -6
- package/esm/expect/api-expect-errors.js +0 -13
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import ruleJudgment from 'rule-judgment';
|
|
2
|
+
import { $parse, ArrayExpression, BooleanLiteral, ComparisonExpression, DateLiteral, LogicalExpression, NullLiteral, NumberLiteral, ParenthesesExpression, QualifiedIdentifier, StringLiteral, TimeLiteral } from '@opra/url';
|
|
1
3
|
import { ApiExpectBody } from './api-expect-body.js';
|
|
2
4
|
export class ApiExpectList extends ApiExpectBody {
|
|
3
5
|
_body;
|
|
@@ -5,12 +7,10 @@ export class ApiExpectList extends ApiExpectBody {
|
|
|
5
7
|
super();
|
|
6
8
|
this._body = _body;
|
|
7
9
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
expect(this._body.items).toBeDefined();
|
|
11
|
-
return this;
|
|
10
|
+
get items() {
|
|
11
|
+
return this._body.items;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
toMatch(value) {
|
|
14
14
|
return this._toMatchObject(this._body.items || [], value);
|
|
15
15
|
}
|
|
16
16
|
haveKeysOnly(keys) {
|
|
@@ -25,4 +25,100 @@ export class ApiExpectList extends ApiExpectBody {
|
|
|
25
25
|
this._notHaveKeys(this._body.items || [], keys);
|
|
26
26
|
return this;
|
|
27
27
|
}
|
|
28
|
+
toBeSortedBy(...fields) {
|
|
29
|
+
const fieldsMap = fields.map(x => x.split('.'));
|
|
30
|
+
const getValue = (obj, fieldMap) => {
|
|
31
|
+
let v = obj;
|
|
32
|
+
let i = 0;
|
|
33
|
+
while (v && i < fieldMap.length) {
|
|
34
|
+
v = v[fieldMap[i++]];
|
|
35
|
+
}
|
|
36
|
+
return v;
|
|
37
|
+
};
|
|
38
|
+
expect(this._body.items).toBeSorted((a, b) => {
|
|
39
|
+
for (const sortField of fieldsMap) {
|
|
40
|
+
const l = getValue(a, sortField);
|
|
41
|
+
const r = getValue(b, sortField);
|
|
42
|
+
if (l < r)
|
|
43
|
+
return -1;
|
|
44
|
+
if (l > r)
|
|
45
|
+
return 1;
|
|
46
|
+
}
|
|
47
|
+
return 0;
|
|
48
|
+
});
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
toBeFilteredBy(filter) {
|
|
52
|
+
const f = convertFilter(filter);
|
|
53
|
+
if (f) {
|
|
54
|
+
const j = ruleJudgment(f);
|
|
55
|
+
const filtered = this._body.items.filter(j);
|
|
56
|
+
expect(this._body.items).toStrictEqual(filtered);
|
|
57
|
+
}
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
toHaveExactItems(expected) {
|
|
61
|
+
return expect(this._body.items.length).toStrictEqual(expected);
|
|
62
|
+
}
|
|
63
|
+
toHaveMaxItems(expected) {
|
|
64
|
+
return expect(this._body.items.length).toBeLessThanOrEqual(expected);
|
|
65
|
+
}
|
|
66
|
+
toHaveMinItems(expected) {
|
|
67
|
+
return expect(this._body.items.length).toBeGreaterThanOrEqual(expected);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export function convertFilter(str) {
|
|
71
|
+
const ast = typeof str === 'string' ? $parse(str) : str;
|
|
72
|
+
if (!ast)
|
|
73
|
+
return;
|
|
74
|
+
if (ast instanceof ComparisonExpression) {
|
|
75
|
+
const left = convertFilter(ast.left);
|
|
76
|
+
const right = convertFilter(ast.right);
|
|
77
|
+
switch (ast.op) {
|
|
78
|
+
case '=':
|
|
79
|
+
return { $eq: { [left]: right } };
|
|
80
|
+
case '!=':
|
|
81
|
+
return { $ne: { [left]: right } };
|
|
82
|
+
case '>':
|
|
83
|
+
return { $gt: { [left]: right } };
|
|
84
|
+
case '>=':
|
|
85
|
+
return { $gte: { [left]: right } };
|
|
86
|
+
case '<':
|
|
87
|
+
return { $lt: { [left]: right } };
|
|
88
|
+
case '<=':
|
|
89
|
+
return { $lte: { [left]: right } };
|
|
90
|
+
case 'in':
|
|
91
|
+
return { $in: { [left]: right } };
|
|
92
|
+
case '!in':
|
|
93
|
+
return { $nin: { [left]: right } };
|
|
94
|
+
default:
|
|
95
|
+
throw new Error(`ComparisonExpression operator (${ast.op}) not implemented yet`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (ast instanceof QualifiedIdentifier) {
|
|
99
|
+
return ast.value;
|
|
100
|
+
}
|
|
101
|
+
if (ast instanceof NumberLiteral ||
|
|
102
|
+
ast instanceof StringLiteral ||
|
|
103
|
+
ast instanceof BooleanLiteral ||
|
|
104
|
+
ast instanceof NullLiteral ||
|
|
105
|
+
ast instanceof DateLiteral ||
|
|
106
|
+
ast instanceof TimeLiteral) {
|
|
107
|
+
return ast.value;
|
|
108
|
+
}
|
|
109
|
+
if (ast instanceof ArrayExpression) {
|
|
110
|
+
return ast.items.map(convertFilter);
|
|
111
|
+
}
|
|
112
|
+
if (ast instanceof LogicalExpression) {
|
|
113
|
+
if (ast.op === 'or')
|
|
114
|
+
return { $or: ast.items.map(convertFilter) };
|
|
115
|
+
return { $and: ast.items.map(convertFilter) };
|
|
116
|
+
}
|
|
117
|
+
if (ast instanceof ArrayExpression) {
|
|
118
|
+
return ast.items.map(convertFilter);
|
|
119
|
+
}
|
|
120
|
+
if (ast instanceof ParenthesesExpression) {
|
|
121
|
+
return convertFilter(ast.expression);
|
|
122
|
+
}
|
|
123
|
+
throw new Error(`${ast.type} is not implemented yet`);
|
|
28
124
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ApiExpectBody } from './api-expect-body.js';
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class ApiExpectObject extends ApiExpectBody {
|
|
3
3
|
protected _body: any;
|
|
4
4
|
constructor(_body: any);
|
|
5
5
|
toBeDefined(): this;
|
|
6
|
-
|
|
6
|
+
toMatch<T extends {}>(value: T): this;
|
|
7
7
|
haveKeysOnly(keys: string[]): this;
|
|
8
8
|
haveKeys(keys: string[]): this;
|
|
9
9
|
notHaveKeys(keys: string[]): this;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ApiExpectBody } from './api-expect-body.js';
|
|
2
|
-
export class
|
|
2
|
+
export class ApiExpectObject extends ApiExpectBody {
|
|
3
3
|
_body;
|
|
4
4
|
constructor(_body) {
|
|
5
5
|
super();
|
|
@@ -9,7 +9,7 @@ export class ApiExpectResource extends ApiExpectBody {
|
|
|
9
9
|
expect(this._body).toBeDefined();
|
|
10
10
|
return this;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
toMatch(value) {
|
|
13
13
|
return this._toMatchObject([this._body], value);
|
|
14
14
|
}
|
|
15
15
|
haveKeysOnly(keys) {
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
+
import './jest-extend.js';
|
|
1
2
|
import { Response } from 'supertest';
|
|
2
|
-
import {
|
|
3
|
+
import { ApiExpectFail } from './api-expect-fail.js';
|
|
3
4
|
import { ApiExpectList } from './api-expect-list.js';
|
|
4
|
-
import {
|
|
5
|
+
import { ApiExpectObject } from './api-expect-object.js';
|
|
5
6
|
export declare class ApiExpect {
|
|
6
7
|
readonly response: Response;
|
|
7
|
-
protected _bodyResource?: ApiExpectResource;
|
|
8
|
-
protected _bodyList?: ApiExpectList;
|
|
9
|
-
protected _bodyErrors?: ApiExpectErrors;
|
|
10
8
|
constructor(response: Response);
|
|
11
|
-
status(value: number): this;
|
|
12
|
-
get bodyAsResource(): ApiExpectResource;
|
|
13
|
-
get bodyAsList(): ApiExpectList;
|
|
14
9
|
toSuccess(status?: number): this;
|
|
15
|
-
|
|
10
|
+
toReturnObject(fn: (body: ApiExpectObject) => void): this;
|
|
11
|
+
toReturnList(fn: (body: ApiExpectList) => void): this;
|
|
12
|
+
toFail(status?: number, fn?: (errors: ApiExpectFail) => void): this;
|
|
16
13
|
}
|
package/esm/expect/api-expect.js
CHANGED
|
@@ -1,33 +1,38 @@
|
|
|
1
|
-
import
|
|
1
|
+
import './jest-extend.js';
|
|
2
|
+
import { ApiExpectFail } from './api-expect-fail.js';
|
|
2
3
|
import { ApiExpectList } from './api-expect-list.js';
|
|
3
|
-
import {
|
|
4
|
+
import { ApiExpectObject } from './api-expect-object.js';
|
|
4
5
|
export class ApiExpect {
|
|
5
6
|
response;
|
|
6
|
-
_bodyResource;
|
|
7
|
-
_bodyList;
|
|
8
|
-
_bodyErrors;
|
|
9
7
|
constructor(response) {
|
|
10
8
|
this.response = response;
|
|
11
9
|
}
|
|
12
|
-
status
|
|
13
|
-
expect(this.response.
|
|
10
|
+
toSuccess(status) {
|
|
11
|
+
expect(this.response.body.errors).toStrictEqual(undefined);
|
|
12
|
+
if (status)
|
|
13
|
+
expect(this.response.status).toEqual(status);
|
|
14
|
+
else {
|
|
15
|
+
expect(this.response.status).toBeGreaterThanOrEqual(200);
|
|
16
|
+
expect(this.response.status).toBeLessThan(300);
|
|
17
|
+
}
|
|
14
18
|
return this;
|
|
15
19
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
toReturnObject(fn) {
|
|
21
|
+
expect(this.response.body).toBeDefined();
|
|
22
|
+
fn(new ApiExpectObject(this.response.body));
|
|
23
|
+
return this;
|
|
19
24
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
toReturnList(fn) {
|
|
26
|
+
expect(this.response.body).toBeDefined();
|
|
27
|
+
expect(this.response.body.items).toBeDefined();
|
|
28
|
+
fn(new ApiExpectList(this.response.body));
|
|
29
|
+
return this;
|
|
23
30
|
}
|
|
24
|
-
|
|
25
|
-
expect(this.response.body.errors).
|
|
31
|
+
toFail(status = 400, fn) {
|
|
32
|
+
expect(this.response.body.errors).toBeDefined();
|
|
26
33
|
expect(this.response.status).toEqual(status);
|
|
34
|
+
if (fn)
|
|
35
|
+
fn(new ApiExpectFail(this.response.body.errors));
|
|
27
36
|
return this;
|
|
28
37
|
}
|
|
29
|
-
get errors() {
|
|
30
|
-
return this._bodyErrors =
|
|
31
|
-
this._bodyErrors || new ApiExpectErrors(this.response.body);
|
|
32
|
-
}
|
|
33
38
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Response } from 'supertest';
|
|
2
|
+
import { BaseTester } from './base-tester.js';
|
|
3
|
+
export interface OpraTesterParams {
|
|
4
|
+
app: any;
|
|
5
|
+
prefix: string;
|
|
6
|
+
headers: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
export declare abstract class BaseOperationTester extends BaseTester {
|
|
9
|
+
send(): Promise<Response>;
|
|
10
|
+
send(fn: (expect: any) => void): Promise<void>;
|
|
11
|
+
protected abstract _send(): Promise<Response>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ApiExpect } from '../expect/api-expect.js';
|
|
2
|
+
import { BaseTester } from './base-tester.js';
|
|
3
|
+
export class BaseOperationTester extends BaseTester {
|
|
4
|
+
async send(fn) {
|
|
5
|
+
const resp = await this._send();
|
|
6
|
+
if (fn) {
|
|
7
|
+
fn(new ApiExpect(resp));
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
return resp;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -4,7 +4,7 @@ export interface OpraTesterParams {
|
|
|
4
4
|
prefix: string;
|
|
5
5
|
headers: Record<string, string>;
|
|
6
6
|
}
|
|
7
|
-
export declare class BaseTester {
|
|
7
|
+
export declare abstract class BaseTester {
|
|
8
8
|
protected readonly _params: OpraTesterParams;
|
|
9
9
|
constructor(params: OpraTesterParams);
|
|
10
10
|
prefix(value: string): this;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { Response } from 'supertest';
|
|
2
2
|
import { CreateQueryOptions } from '@opra/core';
|
|
3
|
-
import {
|
|
3
|
+
import { BaseOperationTester } from './base-operation-tester.js';
|
|
4
4
|
import type { OpraEntityTesterParams } from './entity-tester.js';
|
|
5
5
|
export declare type OpraEntityCreateTesterParams = OpraEntityTesterParams & {
|
|
6
6
|
data: {};
|
|
7
7
|
options: CreateQueryOptions;
|
|
8
8
|
};
|
|
9
|
-
export declare class OpraEntityCreateTester extends
|
|
9
|
+
export declare class OpraEntityCreateTester extends BaseOperationTester {
|
|
10
10
|
protected readonly _params: OpraEntityCreateTesterParams;
|
|
11
11
|
constructor(params: OpraEntityCreateTesterParams);
|
|
12
|
-
send(): Promise<Response>;
|
|
13
12
|
data(data: {}): this;
|
|
14
13
|
omit(...fields: (string | string[])[]): this;
|
|
15
14
|
pick(...fields: (string | string[])[]): this;
|
|
16
15
|
include(...fields: (string | string[])[]): this;
|
|
16
|
+
protected _send(): Promise<Response>;
|
|
17
17
|
}
|
|
@@ -1,24 +1,10 @@
|
|
|
1
1
|
import request from 'supertest';
|
|
2
2
|
import { OpraURL } from '@opra/url';
|
|
3
|
-
import {
|
|
4
|
-
export class OpraEntityCreateTester extends
|
|
3
|
+
import { BaseOperationTester } from './base-operation-tester.js';
|
|
4
|
+
export class OpraEntityCreateTester extends BaseOperationTester {
|
|
5
5
|
constructor(params) {
|
|
6
6
|
super(params);
|
|
7
7
|
}
|
|
8
|
-
async send() {
|
|
9
|
-
const url = new OpraURL(this._params.path);
|
|
10
|
-
url.pathPrefix = this._params.prefix;
|
|
11
|
-
if (this._params.options.include)
|
|
12
|
-
url.searchParams.set('$include', this._params.options.include);
|
|
13
|
-
if (this._params.options.pick)
|
|
14
|
-
url.searchParams.set('$pick', this._params.options.pick);
|
|
15
|
-
if (this._params.options.omit)
|
|
16
|
-
url.searchParams.set('$omit', this._params.options.omit);
|
|
17
|
-
const req = request(this._params.app);
|
|
18
|
-
const test = req.post(url.toString());
|
|
19
|
-
this._prepare(test);
|
|
20
|
-
return test.send(this._params.data);
|
|
21
|
-
}
|
|
22
8
|
data(data) {
|
|
23
9
|
this._params.data = data;
|
|
24
10
|
return this;
|
|
@@ -35,4 +21,18 @@ export class OpraEntityCreateTester extends BaseTester {
|
|
|
35
21
|
this._params.options.include = fields.flat();
|
|
36
22
|
return this;
|
|
37
23
|
}
|
|
24
|
+
async _send() {
|
|
25
|
+
const url = new OpraURL(this._params.path);
|
|
26
|
+
url.pathPrefix = this._params.prefix;
|
|
27
|
+
if (this._params.options.include)
|
|
28
|
+
url.searchParams.set('$include', this._params.options.include);
|
|
29
|
+
if (this._params.options.pick)
|
|
30
|
+
url.searchParams.set('$pick', this._params.options.pick);
|
|
31
|
+
if (this._params.options.omit)
|
|
32
|
+
url.searchParams.set('$omit', this._params.options.omit);
|
|
33
|
+
const req = request(this._params.app);
|
|
34
|
+
const test = req.post(url.toString());
|
|
35
|
+
this._prepare(test);
|
|
36
|
+
return test.send(this._params.data);
|
|
37
|
+
}
|
|
38
38
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Response } from 'supertest';
|
|
2
|
+
import { DeleteManyQueryOption } from '@opra/core';
|
|
3
|
+
import { BaseOperationTester } from './base-operation-tester.js';
|
|
4
|
+
import type { OpraEntityTesterParams } from './entity-tester.js';
|
|
5
|
+
export declare type OpraEntityDeleteManyTesterParams = OpraEntityTesterParams & {
|
|
6
|
+
options: DeleteManyQueryOption;
|
|
7
|
+
};
|
|
8
|
+
export declare class OpraEntityDeleteManyTester extends BaseOperationTester {
|
|
9
|
+
protected readonly _params: OpraEntityDeleteManyTesterParams;
|
|
10
|
+
constructor(params: OpraEntityDeleteManyTesterParams);
|
|
11
|
+
protected _send(): Promise<Response>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import request from 'supertest';
|
|
2
|
+
import { OpraURL } from '@opra/url';
|
|
3
|
+
import { BaseOperationTester } from './base-operation-tester.js';
|
|
4
|
+
export class OpraEntityDeleteManyTester extends BaseOperationTester {
|
|
5
|
+
constructor(params) {
|
|
6
|
+
super(params);
|
|
7
|
+
}
|
|
8
|
+
async _send() {
|
|
9
|
+
const url = new OpraURL(this._params.path);
|
|
10
|
+
url.pathPrefix = this._params.prefix;
|
|
11
|
+
if (this._params.options.filter)
|
|
12
|
+
url.searchParams.set('$filter', this._params.options.filter);
|
|
13
|
+
const req = request(this._params.app);
|
|
14
|
+
const test = req.delete(url.toString());
|
|
15
|
+
this._prepare(test);
|
|
16
|
+
return test.send();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Response } from 'supertest';
|
|
2
|
+
import { CreateQueryOptions } from '@opra/core';
|
|
3
|
+
import { ResourceKey } from '@opra/url';
|
|
4
|
+
import { BaseOperationTester } from './base-operation-tester.js';
|
|
5
|
+
import type { OpraEntityTesterParams } from './entity-tester.js';
|
|
6
|
+
export declare type OpraEntityDeleteTesterParams = OpraEntityTesterParams & {
|
|
7
|
+
keyValue: ResourceKey;
|
|
8
|
+
options: CreateQueryOptions;
|
|
9
|
+
};
|
|
10
|
+
export declare class OpraEntityDeleteTester extends BaseOperationTester {
|
|
11
|
+
protected readonly _params: OpraEntityDeleteTesterParams;
|
|
12
|
+
constructor(params: OpraEntityDeleteTesterParams);
|
|
13
|
+
protected _send(): Promise<Response>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import request from 'supertest';
|
|
2
|
+
import { OpraURL } from '@opra/url';
|
|
3
|
+
import { BaseOperationTester } from './base-operation-tester.js';
|
|
4
|
+
export class OpraEntityDeleteTester extends BaseOperationTester {
|
|
5
|
+
constructor(params) {
|
|
6
|
+
super(params);
|
|
7
|
+
}
|
|
8
|
+
async _send() {
|
|
9
|
+
const url = new OpraURL(this._params.path);
|
|
10
|
+
url.pathPrefix = this._params.prefix;
|
|
11
|
+
url.path.get(url.path.size - 1).key = this._params.keyValue;
|
|
12
|
+
const req = request(this._params.app);
|
|
13
|
+
const test = req.delete(url.toString());
|
|
14
|
+
this._prepare(test);
|
|
15
|
+
return test.send();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Response } from 'supertest';
|
|
2
2
|
import { GetQueryOptions } from '@opra/core';
|
|
3
3
|
import { ResourceKey } from '@opra/url';
|
|
4
|
-
import {
|
|
4
|
+
import { BaseOperationTester } from './base-operation-tester.js';
|
|
5
5
|
import type { OpraEntityTesterParams } from './entity-tester';
|
|
6
6
|
export declare type OpraEntityGetTesterParams = OpraEntityTesterParams & {
|
|
7
7
|
keyValue: ResourceKey;
|
|
8
8
|
options: GetQueryOptions;
|
|
9
9
|
};
|
|
10
|
-
export declare class OpraEntityGetTester extends
|
|
10
|
+
export declare class OpraEntityGetTester extends BaseOperationTester {
|
|
11
11
|
protected readonly _params: OpraEntityGetTesterParams;
|
|
12
12
|
constructor(params: OpraEntityGetTesterParams);
|
|
13
|
-
send(): Promise<Response>;
|
|
14
13
|
keyValue(value: ResourceKey): this;
|
|
15
14
|
omit(...fields: (string | string[])[]): this;
|
|
16
15
|
pick(...fields: (string | string[])[]): this;
|
|
17
16
|
include(...fields: (string | string[])[]): this;
|
|
17
|
+
protected _send(): Promise<Response>;
|
|
18
18
|
}
|
|
@@ -1,25 +1,10 @@
|
|
|
1
1
|
import request from 'supertest';
|
|
2
2
|
import { OpraURL } from '@opra/url';
|
|
3
|
-
import {
|
|
4
|
-
export class OpraEntityGetTester extends
|
|
3
|
+
import { BaseOperationTester } from './base-operation-tester.js';
|
|
4
|
+
export class OpraEntityGetTester extends BaseOperationTester {
|
|
5
5
|
constructor(params) {
|
|
6
6
|
super(params);
|
|
7
7
|
}
|
|
8
|
-
async send() {
|
|
9
|
-
const url = new OpraURL(this._params.path);
|
|
10
|
-
url.pathPrefix = this._params.prefix;
|
|
11
|
-
url.path.get(url.path.size - 1).key = this._params.keyValue;
|
|
12
|
-
if (this._params.options.include)
|
|
13
|
-
url.searchParams.set('$include', this._params.options.include);
|
|
14
|
-
if (this._params.options.pick)
|
|
15
|
-
url.searchParams.set('$pick', this._params.options.pick);
|
|
16
|
-
if (this._params.options.omit)
|
|
17
|
-
url.searchParams.set('$omit', this._params.options.omit);
|
|
18
|
-
const req = request(this._params.app);
|
|
19
|
-
const test = req.get(url.toString());
|
|
20
|
-
this._prepare(test);
|
|
21
|
-
return test.send();
|
|
22
|
-
}
|
|
23
8
|
keyValue(value) {
|
|
24
9
|
this._params.keyValue = value;
|
|
25
10
|
return this;
|
|
@@ -36,4 +21,19 @@ export class OpraEntityGetTester extends BaseTester {
|
|
|
36
21
|
this._params.options.include = fields.flat();
|
|
37
22
|
return this;
|
|
38
23
|
}
|
|
24
|
+
async _send() {
|
|
25
|
+
const url = new OpraURL(this._params.path);
|
|
26
|
+
url.pathPrefix = this._params.prefix;
|
|
27
|
+
url.path.get(url.path.size - 1).key = this._params.keyValue;
|
|
28
|
+
if (this._params.options.include)
|
|
29
|
+
url.searchParams.set('$include', this._params.options.include);
|
|
30
|
+
if (this._params.options.pick)
|
|
31
|
+
url.searchParams.set('$pick', this._params.options.pick);
|
|
32
|
+
if (this._params.options.omit)
|
|
33
|
+
url.searchParams.set('$omit', this._params.options.omit);
|
|
34
|
+
const req = request(this._params.app);
|
|
35
|
+
const test = req.get(url.toString());
|
|
36
|
+
this._prepare(test);
|
|
37
|
+
return test.send();
|
|
38
|
+
}
|
|
39
39
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Response } from 'supertest';
|
|
2
|
+
import { SearchQueryOptions } from '@opra/core';
|
|
3
|
+
import { Expression } from '@opra/url';
|
|
4
|
+
import { BaseOperationTester } from './base-operation-tester.js';
|
|
5
|
+
import type { OpraEntityTesterParams } from './entity-tester';
|
|
6
|
+
export declare type OpraEntitySearchTesterParams = OpraEntityTesterParams & {
|
|
7
|
+
options: SearchQueryOptions;
|
|
8
|
+
};
|
|
9
|
+
export declare class OpraEntitySearchTester extends BaseOperationTester {
|
|
10
|
+
protected readonly _params: OpraEntitySearchTesterParams;
|
|
11
|
+
constructor(params: OpraEntitySearchTesterParams);
|
|
12
|
+
limit(value: number): this;
|
|
13
|
+
skip(value: number): this;
|
|
14
|
+
count(value: boolean): this;
|
|
15
|
+
distinct(value: boolean): this;
|
|
16
|
+
sort(...fields: (string | string[])[]): this;
|
|
17
|
+
filter(value: string | Expression): this;
|
|
18
|
+
omit(...fields: (string | string[])[]): this;
|
|
19
|
+
pick(...fields: (string | string[])[]): this;
|
|
20
|
+
include(...fields: (string | string[])[]): this;
|
|
21
|
+
protected _send(): Promise<Response>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import request from 'supertest';
|
|
2
|
+
import { OpraURL } from '@opra/url';
|
|
3
|
+
import { BaseOperationTester } from './base-operation-tester.js';
|
|
4
|
+
export class OpraEntitySearchTester extends BaseOperationTester {
|
|
5
|
+
constructor(params) {
|
|
6
|
+
super(params);
|
|
7
|
+
}
|
|
8
|
+
limit(value) {
|
|
9
|
+
this._params.options.limit = value;
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
skip(value) {
|
|
13
|
+
this._params.options.skip = value;
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
count(value) {
|
|
17
|
+
this._params.options.count = value;
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
distinct(value) {
|
|
21
|
+
this._params.options.distinct = value;
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
sort(...fields) {
|
|
25
|
+
this._params.options.sort = fields.flat();
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
filter(value) {
|
|
29
|
+
this._params.options.filter = value;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
omit(...fields) {
|
|
33
|
+
this._params.options.omit = fields.flat();
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
pick(...fields) {
|
|
37
|
+
this._params.options.pick = fields.flat();
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
include(...fields) {
|
|
41
|
+
this._params.options.include = fields.flat();
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
async _send() {
|
|
45
|
+
const url = new OpraURL(this._params.path);
|
|
46
|
+
url.pathPrefix = this._params.prefix;
|
|
47
|
+
if (this._params.options.include)
|
|
48
|
+
url.searchParams.set('$include', this._params.options.include);
|
|
49
|
+
if (this._params.options.pick)
|
|
50
|
+
url.searchParams.set('$pick', this._params.options.pick);
|
|
51
|
+
if (this._params.options.omit)
|
|
52
|
+
url.searchParams.set('$omit', this._params.options.omit);
|
|
53
|
+
if (this._params.options.sort)
|
|
54
|
+
url.searchParams.set('$sort', this._params.options.sort);
|
|
55
|
+
if (this._params.options.filter)
|
|
56
|
+
url.searchParams.set('$filter', this._params.options.filter);
|
|
57
|
+
if (this._params.options.limit != null)
|
|
58
|
+
url.searchParams.set('$limit', this._params.options.limit);
|
|
59
|
+
if (this._params.options.skip != null)
|
|
60
|
+
url.searchParams.set('$skip', this._params.options.skip);
|
|
61
|
+
if (this._params.options.count != null)
|
|
62
|
+
url.searchParams.set('$count', this._params.options.count);
|
|
63
|
+
if (this._params.options.distinct != null)
|
|
64
|
+
url.searchParams.set('$distinct', this._params.options.distinct);
|
|
65
|
+
const req = request(this._params.app);
|
|
66
|
+
const test = req.get(url.toString());
|
|
67
|
+
this._prepare(test);
|
|
68
|
+
return test.send();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
import { CreateQueryOptions, GetQueryOptions } from '@opra/core';
|
|
1
|
+
import { CreateQueryOptions, DeleteManyQueryOption, DeleteQueryOptions, GetQueryOptions, UpdateManyQueryOptions, UpdateQueryOptions } from '@opra/core';
|
|
2
2
|
import { ResourceKey } from '@opra/url';
|
|
3
3
|
import { BaseTester, OpraTesterParams } from './base-tester.js';
|
|
4
4
|
import { OpraEntityCreateTester } from './entity-create-tester.js';
|
|
5
|
+
import { OpraEntityDeleteManyTester } from './entity-delete-many-tester.js';
|
|
6
|
+
import { OpraEntityDeleteTester } from './entity-delete-tester.js';
|
|
5
7
|
import { OpraEntityGetTester } from './entity-get-tester.js';
|
|
8
|
+
import { OpraEntitySearchTester } from './entity-search-tester.js';
|
|
9
|
+
import { OpraEntityUpdateManyTester } from './entity-update-many-tester.js';
|
|
10
|
+
import { OpraEntityUpdateTester } from './entity-update-tester.js';
|
|
6
11
|
export declare type OpraEntityTesterParams = OpraTesterParams & {
|
|
7
12
|
path: string;
|
|
8
13
|
};
|
|
9
14
|
export declare class OpraEntityTester extends BaseTester {
|
|
10
15
|
protected readonly _params: OpraEntityTesterParams;
|
|
11
16
|
constructor(params: OpraEntityTesterParams);
|
|
12
|
-
get(keyValue: ResourceKey, options?: GetQueryOptions): OpraEntityGetTester;
|
|
13
17
|
create(data: {}, options?: CreateQueryOptions): OpraEntityCreateTester;
|
|
18
|
+
get(keyValue: ResourceKey, options?: GetQueryOptions): OpraEntityGetTester;
|
|
19
|
+
search(options?: GetQueryOptions): OpraEntitySearchTester;
|
|
20
|
+
update(keyValue: ResourceKey, data: {}, options?: UpdateQueryOptions): OpraEntityUpdateTester;
|
|
21
|
+
updateMany(data: {}, options?: UpdateManyQueryOptions): OpraEntityUpdateManyTester;
|
|
22
|
+
delete(keyValue: ResourceKey, options?: DeleteQueryOptions): OpraEntityDeleteTester;
|
|
23
|
+
deleteMany(options?: DeleteManyQueryOption): OpraEntityDeleteManyTester;
|
|
14
24
|
}
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import { BaseTester } from './base-tester.js';
|
|
2
2
|
import { OpraEntityCreateTester } from './entity-create-tester.js';
|
|
3
|
+
import { OpraEntityDeleteManyTester } from './entity-delete-many-tester.js';
|
|
4
|
+
import { OpraEntityDeleteTester } from './entity-delete-tester.js';
|
|
3
5
|
import { OpraEntityGetTester } from './entity-get-tester.js';
|
|
6
|
+
import { OpraEntitySearchTester } from './entity-search-tester.js';
|
|
7
|
+
import { OpraEntityUpdateManyTester } from './entity-update-many-tester.js';
|
|
8
|
+
import { OpraEntityUpdateTester } from './entity-update-tester.js';
|
|
4
9
|
export class OpraEntityTester extends BaseTester {
|
|
5
10
|
constructor(params) {
|
|
6
11
|
super(params);
|
|
7
12
|
}
|
|
13
|
+
create(data, options = {}) {
|
|
14
|
+
return new OpraEntityCreateTester({
|
|
15
|
+
...this._params,
|
|
16
|
+
headers: { ...this._params.headers },
|
|
17
|
+
data,
|
|
18
|
+
options
|
|
19
|
+
});
|
|
20
|
+
}
|
|
8
21
|
get(keyValue, options = {}) {
|
|
9
22
|
return new OpraEntityGetTester({
|
|
10
23
|
...this._params,
|
|
@@ -13,12 +26,43 @@ export class OpraEntityTester extends BaseTester {
|
|
|
13
26
|
options
|
|
14
27
|
});
|
|
15
28
|
}
|
|
16
|
-
|
|
17
|
-
return new
|
|
29
|
+
search(options = {}) {
|
|
30
|
+
return new OpraEntitySearchTester({
|
|
31
|
+
...this._params,
|
|
32
|
+
headers: { ...this._params.headers },
|
|
33
|
+
options
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
update(keyValue, data, options = {}) {
|
|
37
|
+
return new OpraEntityUpdateTester({
|
|
18
38
|
...this._params,
|
|
39
|
+
keyValue,
|
|
19
40
|
headers: { ...this._params.headers },
|
|
20
41
|
data,
|
|
21
42
|
options
|
|
22
43
|
});
|
|
23
44
|
}
|
|
45
|
+
updateMany(data, options = {}) {
|
|
46
|
+
return new OpraEntityUpdateManyTester({
|
|
47
|
+
...this._params,
|
|
48
|
+
headers: { ...this._params.headers },
|
|
49
|
+
data,
|
|
50
|
+
options
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
delete(keyValue, options = {}) {
|
|
54
|
+
return new OpraEntityDeleteTester({
|
|
55
|
+
...this._params,
|
|
56
|
+
keyValue,
|
|
57
|
+
headers: { ...this._params.headers },
|
|
58
|
+
options
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
deleteMany(options = {}) {
|
|
62
|
+
return new OpraEntityDeleteManyTester({
|
|
63
|
+
...this._params,
|
|
64
|
+
headers: { ...this._params.headers },
|
|
65
|
+
options
|
|
66
|
+
});
|
|
67
|
+
}
|
|
24
68
|
}
|