Page MenuHomeSealhub

user-referenced-in-field.subtest.ts
No OneTemporary

user-referenced-in-field.subtest.ts

import assert from "assert";
import { withStoppedApp } from "../../../test_utils/with-test-app";
import { Collection } from "../../../main";
describe("user-referenced-in-field", () => {
it("should deny if the user isn't the one referenced in the field and allow if it is", async () =>
withStoppedApp(async ({ app, rest_api }) => {
Collection.fromDefinition(app, {
name: "pets",
fields: [
{ name: "name", type: "text" },
{
name: "owner",
type: "single_reference",
params: { collection: "users" },
},
],
access_strategy: {
create: "public",
default: ["user-referenced-in-field", "owner"],
},
});
await app.start();
for (let username of ["Alice", "Bob"]) {
const user = await app.runAction(
new app.Sealious.SuperContext(),
["collections", "users"],
"create",
{
username: username,
password: "password",
email: `${username.toLowerCase()}@example.com`,
}
);
await app.runAction(
new app.Sealious.SuperContext(),
["collections", "pets"],
"create",
{ name: `${username}'s pet`, owner: user.id }
);
}
const alice_session = await rest_api.login({
username: "Alice",
password: "password",
});
const { items } = await rest_api.get(
"/api/v1/collections/pets",
alice_session
);
assert.equal(items.length, 1);
assert.equal(items[0].name, "Alice's pet");
}));
});

File Metadata

Mime Type
text/x-java
Expires
Tue, Dec 24, 14:03 (10 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
557257
Default Alt Text
user-referenced-in-field.subtest.ts (1 KB)

Event Timeline