Page MenuHomeSealhub

settable-by.subtest.ts
No OneTemporary

settable-by.subtest.ts

import assert from "assert";
import axios from "axios";
import { assertThrowsAsync } from "../../../test_utils/assert-throws-async";
import { withRunningApp } from "../../../test_utils/with-test-app";
import { Collection, FieldTypes, Policies } from "../../../main";
import { TestAppType } from "../../../test_utils/test-app";
function extend(t: TestAppType) {
return class extends t {
collections = {
...t.BaseCollections,
"forbidden-collection": new (class extends Collection {
fields = {
any: new FieldTypes.SettableBy(
new FieldTypes.Int(),
new Policies.Noone()
),
};
})(),
"allowed-collection": new (class extends Collection {
fields = {
any: new FieldTypes.SettableBy(
new FieldTypes.Int(),
new Policies.Public()
),
};
})(),
};
};
}
describe("settable-by", async () => {
it("should not allow any value when rejected by access strategy", async () =>
withRunningApp(extend, async ({ base_url }) => {
await assertThrowsAsync(
() =>
axios.post(
`${base_url}/api/v1/collections/forbidden-collection`,
{
any: "thing",
}
),
(e) =>
assert.equal(
e.response.data.data.any.message,
"noone is allowed"
)
);
}));
it("should allow proper value when accepted by access strategy", async () =>
withRunningApp(extend, async ({ base_url, rest_api }) => {
const response = (
await axios.post(
`${base_url}/api/v1/collections/allowed-collection`,
{
any: 1,
}
)
).data;
assert.equal(response.any, 1);
const {
items: [created_item],
} = await rest_api.get(
`/api/v1/collections/allowed-collection/${response.id}`
);
assert.equal(created_item.any, 1);
}));
it("should not allow invalid value when access strategy allows", async () =>
withRunningApp(extend, async ({ base_url }) => {
await assertThrowsAsync(
() =>
axios.post(
`${base_url}/api/v1/collections/allowed-collection`,
{
any: "thing",
}
),
(e) => {
assert.equal(
e.response.data.data.any.message,
"Value 'thing' is not a int number format."
);
}
);
}));
});

File Metadata

Mime Type
text/x-java
Expires
Sat, Sep 20, 14:26 (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
931546
Default Alt Text
settable-by.subtest.ts (2 KB)

Event Timeline