@opra/testing 0.0.11 → 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.
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiExpectResource = void 0;
3
+ exports.ApiExpectObject = void 0;
4
4
  const api_expect_body_js_1 = require("./api-expect-body.js");
5
- class ApiExpectResource extends api_expect_body_js_1.ApiExpectBody {
5
+ class ApiExpectObject extends api_expect_body_js_1.ApiExpectBody {
6
6
  _body;
7
7
  constructor(_body) {
8
8
  super();
@@ -28,4 +28,4 @@ class ApiExpectResource extends api_expect_body_js_1.ApiExpectBody {
28
28
  return this;
29
29
  }
30
30
  }
31
- exports.ApiExpectResource = ApiExpectResource;
31
+ exports.ApiExpectObject = ApiExpectObject;
@@ -4,20 +4,25 @@ exports.ApiExpect = void 0;
4
4
  require("./jest-extend.js");
5
5
  const api_expect_fail_js_1 = require("./api-expect-fail.js");
6
6
  const api_expect_list_js_1 = require("./api-expect-list.js");
7
- const api_expect_resource_js_1 = require("./api-expect-resource.js");
7
+ const api_expect_object_js_1 = require("./api-expect-object.js");
8
8
  class ApiExpect {
9
9
  response;
10
10
  constructor(response) {
11
11
  this.response = response;
12
12
  }
13
- toSuccess(status = 200) {
13
+ toSuccess(status) {
14
14
  expect(this.response.body.errors).toStrictEqual(undefined);
15
- expect(this.response.status).toEqual(status);
15
+ if (status)
16
+ expect(this.response.status).toEqual(status);
17
+ else {
18
+ expect(this.response.status).toBeGreaterThanOrEqual(200);
19
+ expect(this.response.status).toBeLessThan(300);
20
+ }
16
21
  return this;
17
22
  }
18
- toReturnResource(fn) {
23
+ toReturnObject(fn) {
19
24
  expect(this.response.body).toBeDefined();
20
- fn(new api_expect_resource_js_1.ApiExpectResource(this.response.body));
25
+ fn(new api_expect_object_js_1.ApiExpectObject(this.response.body));
21
26
  return this;
22
27
  }
23
28
  toReturnList(fn) {
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpraEntityDeleteManyTester = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const supertest_1 = tslib_1.__importDefault(require("supertest"));
6
+ const url_1 = require("@opra/url");
7
+ const base_operation_tester_js_1 = require("./base-operation-tester.js");
8
+ class OpraEntityDeleteManyTester extends base_operation_tester_js_1.BaseOperationTester {
9
+ constructor(params) {
10
+ super(params);
11
+ }
12
+ async _send() {
13
+ const url = new url_1.OpraURL(this._params.path);
14
+ url.pathPrefix = this._params.prefix;
15
+ if (this._params.options.filter)
16
+ url.searchParams.set('$filter', this._params.options.filter);
17
+ const req = (0, supertest_1.default)(this._params.app);
18
+ const test = req.delete(url.toString());
19
+ this._prepare(test);
20
+ return test.send();
21
+ }
22
+ }
23
+ exports.OpraEntityDeleteManyTester = OpraEntityDeleteManyTester;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpraEntityDeleteTester = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const supertest_1 = tslib_1.__importDefault(require("supertest"));
6
+ const url_1 = require("@opra/url");
7
+ const base_operation_tester_js_1 = require("./base-operation-tester.js");
8
+ class OpraEntityDeleteTester extends base_operation_tester_js_1.BaseOperationTester {
9
+ constructor(params) {
10
+ super(params);
11
+ }
12
+ async _send() {
13
+ const url = new url_1.OpraURL(this._params.path);
14
+ url.pathPrefix = this._params.prefix;
15
+ url.path.get(url.path.size - 1).key = this._params.keyValue;
16
+ const req = (0, supertest_1.default)(this._params.app);
17
+ const test = req.delete(url.toString());
18
+ this._prepare(test);
19
+ return test.send();
20
+ }
21
+ }
22
+ exports.OpraEntityDeleteTester = OpraEntityDeleteTester;
@@ -3,8 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OpraEntityTester = void 0;
4
4
  const base_tester_js_1 = require("./base-tester.js");
5
5
  const entity_create_tester_js_1 = require("./entity-create-tester.js");
6
+ const entity_delete_many_tester_js_1 = require("./entity-delete-many-tester.js");
7
+ const entity_delete_tester_js_1 = require("./entity-delete-tester.js");
6
8
  const entity_get_tester_js_1 = require("./entity-get-tester.js");
7
9
  const entity_search_tester_js_1 = require("./entity-search-tester.js");
10
+ const entity_update_many_tester_js_1 = require("./entity-update-many-tester.js");
8
11
  const entity_update_tester_js_1 = require("./entity-update-tester.js");
9
12
  class OpraEntityTester extends base_tester_js_1.BaseTester {
10
13
  constructor(params) {
@@ -42,5 +45,28 @@ class OpraEntityTester extends base_tester_js_1.BaseTester {
42
45
  options
43
46
  });
44
47
  }
48
+ updateMany(data, options = {}) {
49
+ return new entity_update_many_tester_js_1.OpraEntityUpdateManyTester({
50
+ ...this._params,
51
+ headers: { ...this._params.headers },
52
+ data,
53
+ options
54
+ });
55
+ }
56
+ delete(keyValue, options = {}) {
57
+ return new entity_delete_tester_js_1.OpraEntityDeleteTester({
58
+ ...this._params,
59
+ keyValue,
60
+ headers: { ...this._params.headers },
61
+ options
62
+ });
63
+ }
64
+ deleteMany(options = {}) {
65
+ return new entity_delete_many_tester_js_1.OpraEntityDeleteManyTester({
66
+ ...this._params,
67
+ headers: { ...this._params.headers },
68
+ options
69
+ });
70
+ }
45
71
  }
46
72
  exports.OpraEntityTester = OpraEntityTester;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpraEntityUpdateManyTester = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const supertest_1 = tslib_1.__importDefault(require("supertest"));
6
+ const url_1 = require("@opra/url");
7
+ const base_operation_tester_js_1 = require("./base-operation-tester.js");
8
+ class OpraEntityUpdateManyTester extends base_operation_tester_js_1.BaseOperationTester {
9
+ constructor(params) {
10
+ super(params);
11
+ }
12
+ data(data) {
13
+ this._params.data = data;
14
+ return this;
15
+ }
16
+ async _send() {
17
+ const url = new url_1.OpraURL(this._params.path);
18
+ url.pathPrefix = this._params.prefix;
19
+ if (this._params.options.filter)
20
+ url.searchParams.set('$filter', this._params.options.filter);
21
+ const req = (0, supertest_1.default)(this._params.app);
22
+ const test = req.patch(url.toString());
23
+ this._prepare(test);
24
+ return test.send(this._params.data);
25
+ }
26
+ }
27
+ exports.OpraEntityUpdateManyTester = OpraEntityUpdateManyTester;
@@ -36,7 +36,7 @@ class OpraEntityUpdateTester extends base_operation_tester_js_1.BaseOperationTes
36
36
  if (this._params.options.omit)
37
37
  url.searchParams.set('$omit', this._params.options.omit);
38
38
  const req = (0, supertest_1.default)(this._params.app);
39
- const test = req.post(url.toString());
39
+ const test = req.patch(url.toString());
40
40
  this._prepare(test);
41
41
  return test.send(this._params.data);
42
42
  }
@@ -1,5 +1,5 @@
1
1
  import { ApiExpectBody } from './api-expect-body.js';
2
- export declare class ApiExpectResource extends ApiExpectBody {
2
+ export declare class ApiExpectObject extends ApiExpectBody {
3
3
  protected _body: any;
4
4
  constructor(_body: any);
5
5
  toBeDefined(): this;
@@ -1,5 +1,5 @@
1
1
  import { ApiExpectBody } from './api-expect-body.js';
2
- export class ApiExpectResource extends ApiExpectBody {
2
+ export class ApiExpectObject extends ApiExpectBody {
3
3
  _body;
4
4
  constructor(_body) {
5
5
  super();
@@ -2,12 +2,12 @@ import './jest-extend.js';
2
2
  import { Response } from 'supertest';
3
3
  import { ApiExpectFail } from './api-expect-fail.js';
4
4
  import { ApiExpectList } from './api-expect-list.js';
5
- import { ApiExpectResource } from './api-expect-resource.js';
5
+ import { ApiExpectObject } from './api-expect-object.js';
6
6
  export declare class ApiExpect {
7
7
  readonly response: Response;
8
8
  constructor(response: Response);
9
9
  toSuccess(status?: number): this;
10
- toReturnResource(fn: (body: ApiExpectResource) => void): this;
10
+ toReturnObject(fn: (body: ApiExpectObject) => void): this;
11
11
  toReturnList(fn: (body: ApiExpectList) => void): this;
12
12
  toFail(status?: number, fn?: (errors: ApiExpectFail) => void): this;
13
13
  }
@@ -1,20 +1,25 @@
1
1
  import './jest-extend.js';
2
2
  import { ApiExpectFail } from './api-expect-fail.js';
3
3
  import { ApiExpectList } from './api-expect-list.js';
4
- import { ApiExpectResource } from './api-expect-resource.js';
4
+ import { ApiExpectObject } from './api-expect-object.js';
5
5
  export class ApiExpect {
6
6
  response;
7
7
  constructor(response) {
8
8
  this.response = response;
9
9
  }
10
- toSuccess(status = 200) {
10
+ toSuccess(status) {
11
11
  expect(this.response.body.errors).toStrictEqual(undefined);
12
- expect(this.response.status).toEqual(status);
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
+ }
13
18
  return this;
14
19
  }
15
- toReturnResource(fn) {
20
+ toReturnObject(fn) {
16
21
  expect(this.response.body).toBeDefined();
17
- fn(new ApiExpectResource(this.response.body));
22
+ fn(new ApiExpectObject(this.response.body));
18
23
  return this;
19
24
  }
20
25
  toReturnList(fn) {
@@ -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,9 +1,12 @@
1
- import { CreateQueryOptions, GetQueryOptions, UpdateQueryOptions } 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';
6
8
  import { OpraEntitySearchTester } from './entity-search-tester.js';
9
+ import { OpraEntityUpdateManyTester } from './entity-update-many-tester.js';
7
10
  import { OpraEntityUpdateTester } from './entity-update-tester.js';
8
11
  export declare type OpraEntityTesterParams = OpraTesterParams & {
9
12
  path: string;
@@ -15,4 +18,7 @@ export declare class OpraEntityTester extends BaseTester {
15
18
  get(keyValue: ResourceKey, options?: GetQueryOptions): OpraEntityGetTester;
16
19
  search(options?: GetQueryOptions): OpraEntitySearchTester;
17
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;
18
24
  }
@@ -1,7 +1,10 @@
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';
4
6
  import { OpraEntitySearchTester } from './entity-search-tester.js';
7
+ import { OpraEntityUpdateManyTester } from './entity-update-many-tester.js';
5
8
  import { OpraEntityUpdateTester } from './entity-update-tester.js';
6
9
  export class OpraEntityTester extends BaseTester {
7
10
  constructor(params) {
@@ -39,4 +42,27 @@ export class OpraEntityTester extends BaseTester {
39
42
  options
40
43
  });
41
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
+ }
42
68
  }
@@ -0,0 +1,14 @@
1
+ import { Response } from 'supertest';
2
+ import { UpdateManyQueryOptions } from '@opra/core';
3
+ import { BaseOperationTester } from './base-operation-tester.js';
4
+ import type { OpraEntityTesterParams } from './entity-tester.js';
5
+ export declare type OpraEntityUpdateManyTesterParams = OpraEntityTesterParams & {
6
+ data: {};
7
+ options: UpdateManyQueryOptions;
8
+ };
9
+ export declare class OpraEntityUpdateManyTester extends BaseOperationTester {
10
+ protected readonly _params: OpraEntityUpdateManyTesterParams;
11
+ constructor(params: OpraEntityUpdateManyTesterParams);
12
+ data(data: {}): this;
13
+ protected _send(): Promise<Response>;
14
+ }
@@ -0,0 +1,22 @@
1
+ import request from 'supertest';
2
+ import { OpraURL } from '@opra/url';
3
+ import { BaseOperationTester } from './base-operation-tester.js';
4
+ export class OpraEntityUpdateManyTester extends BaseOperationTester {
5
+ constructor(params) {
6
+ super(params);
7
+ }
8
+ data(data) {
9
+ this._params.data = data;
10
+ return this;
11
+ }
12
+ async _send() {
13
+ const url = new OpraURL(this._params.path);
14
+ url.pathPrefix = this._params.prefix;
15
+ if (this._params.options.filter)
16
+ url.searchParams.set('$filter', this._params.options.filter);
17
+ const req = request(this._params.app);
18
+ const test = req.patch(url.toString());
19
+ this._prepare(test);
20
+ return test.send(this._params.data);
21
+ }
22
+ }
@@ -1,16 +1,16 @@
1
1
  import { Response } from 'supertest';
2
- import { CreateQueryOptions } from '@opra/core';
2
+ import { UpdateQueryOptions } from '@opra/core';
3
3
  import { ResourceKey } from '@opra/url';
4
4
  import { BaseOperationTester } from './base-operation-tester.js';
5
5
  import type { OpraEntityTesterParams } from './entity-tester.js';
6
- export declare type OpraEntityCreateTesterParams = OpraEntityTesterParams & {
7
- data: {};
6
+ export declare type OpraEntityUpdateTesterParams = OpraEntityTesterParams & {
8
7
  keyValue: ResourceKey;
9
- options: CreateQueryOptions;
8
+ data: {};
9
+ options: UpdateQueryOptions;
10
10
  };
11
11
  export declare class OpraEntityUpdateTester extends BaseOperationTester {
12
- protected readonly _params: OpraEntityCreateTesterParams;
13
- constructor(params: OpraEntityCreateTesterParams);
12
+ protected readonly _params: OpraEntityUpdateTesterParams;
13
+ constructor(params: OpraEntityUpdateTesterParams);
14
14
  data(data: {}): this;
15
15
  omit(...fields: (string | string[])[]): this;
16
16
  pick(...fields: (string | string[])[]): this;
@@ -32,7 +32,7 @@ export class OpraEntityUpdateTester extends BaseOperationTester {
32
32
  if (this._params.options.omit)
33
33
  url.searchParams.set('$omit', this._params.options.omit);
34
34
  const req = request(this._params.app);
35
- const test = req.post(url.toString());
35
+ const test = req.patch(url.toString());
36
36
  this._prepare(test);
37
37
  return test.send(this._params.data);
38
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/testing",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "Opra testing package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -25,8 +25,8 @@
25
25
  "clean:cover": "rimraf ../../coverage/testing"
26
26
  },
27
27
  "dependencies": {
28
- "@opra/core": "^0.0.11",
29
- "@opra/url": "^0.0.11",
28
+ "@opra/core": "^0.0.12",
29
+ "@opra/url": "^0.0.12",
30
30
  "lodash": "^4.17.21",
31
31
  "rule-judgment": "^1.1.5",
32
32
  "supertest": "^6.2.4"