-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(rest-api-client): Divide the tests code for AppClient and Re…
…cordClient (#2880)
- Loading branch information
Showing
23 changed files
with
3,022 additions
and
2,819 deletions.
There are no files selected for viewing
1,467 changes: 5 additions & 1,462 deletions
1,467
packages/rest-api-client/src/client/__tests__/AppClient.test.ts
Large diffs are not rendered by default.
Oops, something went wrong.
1,362 changes: 5 additions & 1,357 deletions
1,362
packages/rest-api-client/src/client/__tests__/RecordClient.test.ts
Large diffs are not rendered by default.
Oops, something went wrong.
231 changes: 231 additions & 0 deletions
231
packages/rest-api-client/src/client/__tests__/app/Acl.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,231 @@ | ||
import type { MockClient } from "../../../http/MockClient"; | ||
import type { AppClient } from "../../AppClient"; | ||
import { APP_ID, makeClients, REVISION } from "../fixtures/AppClientFixture"; | ||
|
||
const RECORD_ID = 3; | ||
|
||
describe("Acl", () => { | ||
let mockClient: MockClient; | ||
let appClient: AppClient; | ||
|
||
beforeEach(() => { | ||
const clients = makeClients(); | ||
appClient = clients.appClient; | ||
mockClient = clients.mockClient; | ||
}); | ||
|
||
describe("getFieldAcl", () => { | ||
const params = { | ||
app: APP_ID, | ||
}; | ||
beforeEach(async () => { | ||
await appClient.getFieldAcl(params); | ||
}); | ||
it("should pass the path to the http client", () => { | ||
expect(mockClient.getLogs()[0].path).toBe("/k/v1/field/acl.json"); | ||
}); | ||
it("should send a get request", () => { | ||
expect(mockClient.getLogs()[0].method).toBe("get"); | ||
}); | ||
it("should pass app as a param to the http client", () => { | ||
expect(mockClient.getLogs()[0].params).toEqual(params); | ||
}); | ||
}); | ||
|
||
describe("updateFieldAcl", () => { | ||
const params = { | ||
app: APP_ID, | ||
rights: [ | ||
{ | ||
code: "foo", | ||
entities: [ | ||
{ | ||
accessibility: "READ" as const, | ||
entity: { | ||
code: "bar", | ||
type: "USER" as const, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
beforeEach(async () => { | ||
await appClient.updateFieldAcl(params); | ||
}); | ||
it("should pass the path to the http client", () => { | ||
expect(mockClient.getLogs()[0].path).toBe("/k/v1/preview/field/acl.json"); | ||
}); | ||
it("should send a put request", () => { | ||
expect(mockClient.getLogs()[0].method).toBe("put"); | ||
}); | ||
it("should pass app and rights as a param to the http client", () => { | ||
expect(mockClient.getLogs()[0].params).toEqual(params); | ||
}); | ||
}); | ||
|
||
describe("getRecordAcl", () => { | ||
const lang = "default"; | ||
const params = { | ||
app: APP_ID, | ||
lang, | ||
} as const; | ||
describe("without preview", () => { | ||
beforeEach(async () => { | ||
await appClient.getRecordAcl(params); | ||
}); | ||
it("should pass the path to the http client", () => { | ||
expect(mockClient.getLogs()[0].path).toBe("/k/v1/record/acl.json"); | ||
}); | ||
it("should send a get request", () => { | ||
expect(mockClient.getLogs()[0].method).toBe("get"); | ||
}); | ||
it("should pass app and lang as a param to the http client", () => { | ||
expect(mockClient.getLogs()[0].params).toEqual(params); | ||
}); | ||
}); | ||
describe("preview: true", () => { | ||
beforeEach(async () => { | ||
await appClient.getRecordAcl({ ...params, preview: true }); | ||
}); | ||
it("should pass the path to the http client", () => { | ||
expect(mockClient.getLogs()[0].path).toBe( | ||
"/k/v1/preview/record/acl.json", | ||
); | ||
}); | ||
it("should send a get request", () => { | ||
expect(mockClient.getLogs()[0].method).toBe("get"); | ||
}); | ||
it("should pass app and lang as a param to the http client", () => { | ||
expect(mockClient.getLogs()[0].params).toEqual(params); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("updateRecordAcl", () => { | ||
const params = { | ||
app: APP_ID, | ||
rights: [ | ||
{ | ||
filterCond: 'field = "foo"', | ||
entities: [ | ||
{ | ||
entity: { | ||
code: "bar", | ||
type: "USER" as const, | ||
}, | ||
viewable: false, | ||
editable: false, | ||
deletable: false, | ||
includeSubs: true, | ||
}, | ||
], | ||
}, | ||
], | ||
revision: REVISION, | ||
}; | ||
beforeEach(async () => { | ||
await appClient.updateRecordAcl(params); | ||
}); | ||
it("should pass the path to the http client", () => { | ||
expect(mockClient.getLogs()[0].path).toBe( | ||
"/k/v1/preview/record/acl.json", | ||
); | ||
}); | ||
it("should send a put request", () => { | ||
expect(mockClient.getLogs()[0].method).toBe("put"); | ||
}); | ||
it("should pass app, right and revision as a param to the http client", () => { | ||
expect(mockClient.getLogs()[0].params).toEqual(params); | ||
}); | ||
}); | ||
|
||
describe("getAppAcl", () => { | ||
const params = { | ||
app: APP_ID, | ||
}; | ||
describe("without preview", () => { | ||
beforeEach(async () => { | ||
await appClient.getAppAcl(params); | ||
}); | ||
it("should pass the path to the http client", () => { | ||
expect(mockClient.getLogs()[0].path).toBe("/k/v1/app/acl.json"); | ||
}); | ||
it("should send a get request", () => { | ||
expect(mockClient.getLogs()[0].method).toBe("get"); | ||
}); | ||
it("should pass app as a param to the http client", () => { | ||
expect(mockClient.getLogs()[0].params).toEqual(params); | ||
}); | ||
}); | ||
describe("preview: true", () => { | ||
beforeEach(async () => { | ||
await appClient.getAppAcl({ ...params, preview: true }); | ||
}); | ||
it("should pass the path to the http client", () => { | ||
expect(mockClient.getLogs()[0].path).toBe("/k/v1/preview/app/acl.json"); | ||
}); | ||
it("should send a get request", () => { | ||
expect(mockClient.getLogs()[0].method).toBe("get"); | ||
}); | ||
it("should pass app and preview as a param to the http client", () => { | ||
expect(mockClient.getLogs()[0].params).toEqual(params); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("updateAppAcl", () => { | ||
const params = { | ||
app: APP_ID, | ||
rights: [ | ||
{ | ||
entity: { | ||
type: "USER" as const, | ||
code: "foo", | ||
}, | ||
appEditable: true, | ||
recordViewable: true, | ||
recordAddable: true, | ||
recordEditable: true, | ||
recordDeletable: true, | ||
recordImportable: true, | ||
recordExportable: true, | ||
}, | ||
], | ||
}; | ||
beforeEach(async () => { | ||
await appClient.updateAppAcl(params); | ||
}); | ||
it("should pass the path to the http client", () => { | ||
expect(mockClient.getLogs()[0].path).toBe("/k/v1/preview/app/acl.json"); | ||
}); | ||
it("should send a put request", () => { | ||
expect(mockClient.getLogs()[0].method).toBe("put"); | ||
}); | ||
it("should pass app and rights as a param to the http client", () => { | ||
expect(mockClient.getLogs()[0].params).toEqual(params); | ||
}); | ||
}); | ||
|
||
describe("evaluateRecordsAcl", () => { | ||
const params = { | ||
app: APP_ID, | ||
ids: [RECORD_ID], | ||
}; | ||
beforeEach(async () => { | ||
await appClient.evaluateRecordsAcl(params); | ||
}); | ||
it("should pass the path to the http client", () => { | ||
expect(mockClient.getLogs()[0].path).toBe( | ||
"/k/v1/records/acl/evaluate.json", | ||
); | ||
}); | ||
it("should send a get request", () => { | ||
expect(mockClient.getLogs()[0].method).toBe("get"); | ||
}); | ||
it("should pass app and ids as a param to the http client", () => { | ||
expect(mockClient.getLogs()[0].params).toEqual(params); | ||
}); | ||
}); | ||
}); |
103 changes: 103 additions & 0 deletions
103
packages/rest-api-client/src/client/__tests__/app/Actions.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,103 @@ | ||
import type { MockClient } from "../../../http/MockClient"; | ||
import type { AppClient } from "../../AppClient"; | ||
import { APP_ID, makeClients } from "../fixtures/AppClientFixture"; | ||
|
||
describe("Actions", () => { | ||
let mockClient: MockClient; | ||
let appClient: AppClient; | ||
|
||
beforeEach(() => { | ||
const clients = makeClients(); | ||
appClient = clients.appClient; | ||
mockClient = clients.mockClient; | ||
}); | ||
|
||
describe("getAppActions", () => { | ||
const lang = "default"; | ||
const params = { app: APP_ID, lang } as const; | ||
describe("without preview", () => { | ||
beforeEach(async () => { | ||
await appClient.getAppActions(params); | ||
}); | ||
it("should pass the path to the http client", () => { | ||
expect(mockClient.getLogs()[0].path).toBe("/k/v1/app/actions.json"); | ||
}); | ||
it("should send a get request", () => { | ||
expect(mockClient.getLogs()[0].method).toBe("get"); | ||
}); | ||
it("should pass app and lang as a param to the http client", () => { | ||
expect(mockClient.getLogs()[0].params).toEqual(params); | ||
}); | ||
}); | ||
describe("preview: true", () => { | ||
beforeEach(async () => { | ||
await appClient.getAppActions({ | ||
...params, | ||
preview: true, | ||
}); | ||
}); | ||
it("should pass the path to the http client", () => { | ||
expect(mockClient.getLogs()[0].path).toBe( | ||
"/k/v1/preview/app/actions.json", | ||
); | ||
}); | ||
it("should send a get request", () => { | ||
expect(mockClient.getLogs()[0].method).toBe("get"); | ||
}); | ||
it("should pass app and lang as a param to the http client", () => { | ||
expect(mockClient.getLogs()[0].params).toEqual(params); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("updateAppActions", () => { | ||
const params = { | ||
app: APP_ID, | ||
actions: { | ||
Action_A: { | ||
name: "Action_A", | ||
index: "0", | ||
destApp: { | ||
code: "INVOICE", | ||
}, | ||
mappings: [ | ||
{ | ||
srcType: "FIELD" as const, | ||
srcField: "CompanyName", | ||
destField: "CompanyName", | ||
}, | ||
{ | ||
srcType: "FIELD" as const, | ||
srcField: "DivisionName", | ||
destField: "DivisionName", | ||
}, | ||
{ | ||
srcType: "RECORD_URL" as const, | ||
destField: "URL", | ||
}, | ||
], | ||
entities: [ | ||
{ | ||
type: "USER" as const, | ||
code: "Administrator", | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
beforeEach(async () => { | ||
await appClient.updateAppActions(params); | ||
}); | ||
it("should pass the path to the http client", () => { | ||
expect(mockClient.getLogs()[0].path).toBe( | ||
"/k/v1/preview/app/actions.json", | ||
); | ||
}); | ||
it("should send a put request", () => { | ||
expect(mockClient.getLogs()[0].method).toBe("put"); | ||
}); | ||
it("should pass app and actions as a param to the http client", () => { | ||
expect(mockClient.getLogs()[0].params).toEqual(params); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.