Skip to content

Commit

Permalink
refactor(rest-api-client): Divide the tests code for AppClient and Re…
Browse files Browse the repository at this point in the history
…cordClient (#2880)
  • Loading branch information
shabaraba authored Jul 30, 2024
1 parent c79c0fc commit 5e9d42d
Show file tree
Hide file tree
Showing 23 changed files with 3,022 additions and 2,819 deletions.
1,467 changes: 5 additions & 1,462 deletions packages/rest-api-client/src/client/__tests__/AppClient.test.ts

Large diffs are not rendered by default.

1,362 changes: 5 additions & 1,357 deletions packages/rest-api-client/src/client/__tests__/RecordClient.test.ts

Large diffs are not rendered by default.

231 changes: 231 additions & 0 deletions packages/rest-api-client/src/client/__tests__/app/Acl.test.ts
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 packages/rest-api-client/src/client/__tests__/app/Actions.test.ts
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);
});
});
});
Loading

0 comments on commit 5e9d42d

Please sign in to comment.