Changeset View
Changeset View
Standalone View
Standalone View
lib/app/base-chips/access-strategy-types/not.subtest.js
const assert = require("assert"); | |||||
const locreq = require("locreq")(__dirname); | const locreq = require("locreq")(__dirname); | ||||
const assert = require("assert"); | |||||
const Promise = require("bluebird"); | const Promise = require("bluebird"); | ||||
const { with_running_app } = locreq("test_utils/with-test-app.js"); | const { with_running_app } = locreq("test_utils/with-test-app.js"); | ||||
const assert_throws_async = locreq("test_utils/assert_throws_async.js"); | const assert_throws_async = locreq("test_utils/assert_throws_async.js"); | ||||
describe("NotAccessStrategy", () => { | describe("NotAccessStrategy", () => { | ||||
let port; | |||||
async function setup(app) { | async function setup(app) { | ||||
port = app.ConfigManager.get("www-server.port"); | |||||
app.createChip(Sealious.Collection, { | app.createChip(Sealious.Collection, { | ||||
name: "numbers", | name: "numbers", | ||||
fields: [ | fields: [ | ||||
{ | { | ||||
name: "number", | name: "number", | ||||
type: "int", | type: "int", | ||||
}, | }, | ||||
], | ], | ||||
Show All 18 Lines | const collections = [ | ||||
{ | { | ||||
name: "collection-not(noone)", | name: "collection-not(noone)", | ||||
strategy: ["noone"], | strategy: ["noone"], | ||||
}, | }, | ||||
]; | ]; | ||||
for (const { name, strategy } of collections) { | for (const { name, strategy } of collections) { | ||||
app.createChip(Sealious.Collection, { | app.createChip(Sealious.Collection, { | ||||
name: name, | name, | ||||
fields: [ | fields: [ | ||||
{ | { | ||||
name: "number", | name: "number", | ||||
type: "single_reference", | type: "single_reference", | ||||
params: { collection: "numbers" }, | params: { collection: "numbers" }, | ||||
required: true, | required: true, | ||||
}, | }, | ||||
], | ], | ||||
Show All 21 Lines | for (let i of [0, 1, 2, 3, 4]) { | ||||
) | ) | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
function create_less_than_strategy(app, number) { | function create_less_than_strategy(app, number) { | ||||
app.createChip(app.Sealious.AccessStrategyType, { | app.createChip(app.Sealious.AccessStrategyType, { | ||||
name: `less-than(${number})`, | name: `less-than(${number})`, | ||||
getRestrictingQuery: async function() { | async getRestrictingQuery() { | ||||
const query = new app.Query(); | const query = new app.Query(); | ||||
const id = query.lookup({ | const id = query.lookup({ | ||||
from: "numbers", | from: "numbers", | ||||
localField: "number", | localField: "number", | ||||
foreignField: "sealious_id", | foreignField: "sealious_id", | ||||
}); | }); | ||||
query.match({ | query.match({ | ||||
[`${id}.number`]: { | [`${id}.number`]: { | ||||
$lt: number, | $lt: number, | ||||
}, | }, | ||||
}); | }); | ||||
return query; | return query; | ||||
}, | }, | ||||
checker_function: async function(context, params, item) { | async checker_function(context, params, item) { | ||||
if (item.number.number >= number) { | if (item.number.number >= number) { | ||||
return Promise.reject( | return Promise.reject( | ||||
`Given value is not lower than ${number}` | `Given value is not lower than ${number}` | ||||
); | ); | ||||
} | } | ||||
}, | }, | ||||
item_sensitive: true, | item_sensitive: true, | ||||
}); | }); | ||||
} | } | ||||
it("returns nothing for collection-not(public)", () => | it("returns nothing for collection-not(public)", () => | ||||
with_running_app(async ({ app, rest_api }) => { | with_running_app(async ({ app, rest_api }) => { | ||||
await setup(app); | await setup(app); | ||||
await assert_throws_async( | await assert_throws_async( | ||||
async () => | () => | ||||
await rest_api.get( | rest_api.get("/api/v1/collections/collection-not(public)"), | ||||
"/api/v1/collections/collection-not(public)" | |||||
), | |||||
e => { | e => { | ||||
assert.equal(e.response.status, 401); | assert.equal(e.response.status, 401); | ||||
} | } | ||||
); | ); | ||||
})); | })); | ||||
it("returns everything for collection-not(noone)", () => | it("returns everything for collection-not(noone)", () => | ||||
with_running_app(async ({ app, rest_api }) => { | with_running_app(async ({ app, rest_api }) => { | ||||
Show All 28 Lines |