Page MenuHomeSealhub

or.test.ts
No OneTemporary

or.test.ts

import assert from "assert";
import Bluebird from "bluebird";
import { TestAppConstructor, withRunningApp } from "../../test_utils/with-test-app.js";
import create_policies from "../../test_utils/policy-types/create-policies-with-complex-pipeline.js";
import type * as Sealious from "../../main.js";
import { Collection, FieldTypes, Policies, Policy } from "../../main.js";
import { TestApp } from "../../test_utils/test-app.js";
const [ComplexDenyPipeline, ComplexAllowPipeline] = create_policies.allowDeny();
const collections = [
{
name: "collection-or(nested-or(allow,noone),nested-and(allow,public))",
policies: [
new Policies.Or([new ComplexAllowPipeline(), new Policies.Noone()]),
new Policies.And([new ComplexAllowPipeline(), new Policies.Public()]),
],
},
{
name: "collection-or(complex-allow-pipeline,public)",
policies: [new ComplexAllowPipeline(), new Policies.Public()],
},
{
name: "collection-or(complex-deny-pipeline,noone)",
policies: [new ComplexDenyPipeline(), new Policies.Noone()],
},
{
name: "collection-or(complex-deny-pipeline,public)",
policies: [new ComplexDenyPipeline(), new Policies.Public()],
},
];
function extend(t: TestAppConstructor) {
const numbers = new (class extends Collection {
name = "numbers";
fields = {
number: new FieldTypes.Int(),
};
})();
const collections_to_add: { [collection: string]: Collection } = {
numbers,
};
for (const { name, policies } of collections) {
collections_to_add[name] = new (class extends Collection {
name = name;
fields = {
number: new FieldTypes.SingleReference("numbers"),
};
policies = {
list: new Policies.Or(policies),
show: new Policies.Or(policies),
create: new Policies.Public(),
};
})();
}
return class extends t {
collections = {
...TestApp.BaseCollections,
...collections_to_add,
numbers,
};
};
}
async function createItems(app: Sealious.App) {
let numbers = await Bluebird.map([0, 1, 2], (n) =>
app.collections.numbers.suCreate({ number: n })
);
for (const number of numbers) {
await Bluebird.map(collections, ({ name }) =>
app.collections[name].suCreate({
number: number.id,
})
);
}
}
describe("OrPolicy", () => {
it("returns everything for collection-or(nested-or(allow,noone),nested-and(allow,public))", () =>
withRunningApp(extend, async ({ app, rest_api }) => {
await createItems(app);
return rest_api
.get(
"/api/v1/collections/collection-or(nested-or(allow,noone),nested-and(allow,public))"
)
.then(({ items }: any) => assert.equal(items.length, 3));
}));
it("returns everything for or(complex-allow-pipeline,public)", () =>
withRunningApp(extend, async ({ app, rest_api }) => {
await createItems(app);
return rest_api
.get("/api/v1/collections/collection-or(complex-allow-pipeline,public)")
.then(({ items }: any) => assert.equal(items.length, 3));
}));
it("returns nothing for or(complex-deny-pipeline,noone)", () =>
withRunningApp(extend, async ({ app, rest_api }) => {
await createItems(app);
return rest_api
.get("/api/v1/collections/collection-or(complex-deny-pipeline,noone)")
.then(({ items }: any) => assert.equal(items.length, 0));
}));
it("returns everything for or(complex-deny-pipeline,public)", () =>
withRunningApp(extend, async ({ app, rest_api }) => {
await createItems(app);
return rest_api
.get("/api/v1/collections/collection-or(complex-deny-pipeline,public)")
.then(({ items }: any) => assert.equal(items.length, 3));
}));
});

File Metadata

Mime Type
text/x-java
Expires
Tue, Dec 24, 02:16 (23 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
557014
Default Alt Text
or.test.ts (3 KB)

Event Timeline