Changeset View
Changeset View
Standalone View
Standalone View
lib/app/base-chips/access-strategy-types/not.subtest.js
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | for (const { name, strategy } of collections) { | ||||
], | ], | ||||
access_strategy: { | access_strategy: { | ||||
show: ["not", strategy], | show: ["not", strategy], | ||||
create: "public", | create: "public", | ||||
}, | }, | ||||
}); | }); | ||||
} | } | ||||
let numbers = await Promise.map([0, 1, 2, 3, 4], n => | for (let i of [0, 1, 2, 3, 4]) { | ||||
app.run_action( | const { id } = await app.run_action( | ||||
new app.Sealious.SuperContext(), | new app.Sealious.SuperContext(), | ||||
["collections", "numbers"], | ["collections", "numbers"], | ||||
"create", | "create", | ||||
{ number: n } | { number: i } | ||||
) | |||||
); | ); | ||||
for (const number of numbers) { | |||||
await Promise.map(collections, ({ name }) => | await Promise.map(collections, ({ name }) => | ||||
app.run_action( | app.run_action( | ||||
new app.Sealious.SuperContext(), | new app.Sealious.SuperContext(), | ||||
["collections", name], | ["collections", name], | ||||
"create", | "create", | ||||
{ number: number.id } | { number: id } | ||||
) | ) | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
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() { | getRestrictingQuery: async function() { | ||||
const query = new app.Query(); | const query = new app.Query(); | ||||
const id = query.lookup({ | const id = query.lookup({ | ||||
from: "numbers", | from: "numbers", | ||||
localField: "body.number", | localField: "number", | ||||
foreignField: "sealious_id", | foreignField: "sealious_id", | ||||
}); | }); | ||||
query.match({ | query.match({ | ||||
[`${id}.body.number`]: { | [`${id}.number`]: { | ||||
$lt: number, | $lt: number, | ||||
}, | }, | ||||
}); | }); | ||||
return query; | return query; | ||||
}, | }, | ||||
checker_function: async function(context, params, item) { | checker_function: async function(context, params, item) { | ||||
if (item.body.number.body.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, | ||||
}); | }); | ||||
} | } | ||||
Show All 12 Lines | with_running_app(async ({ app, rest_api }) => { | ||||
); | ); | ||||
})); | })); | ||||
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 }) => { | ||||
await setup(app); | await setup(app); | ||||
const numbers = (await rest_api.get( | const numbers = (await rest_api.get( | ||||
"/api/v1/collections/collection-not(noone)?format%5Bnumber%5D=expand" | "/api/v1/collections/collection-not(noone)?format%5Bnumber%5D=expand" | ||||
)).items.map(n => n.body.number.body.number); | )).items.map(n => n.number.number); | ||||
assert.deepEqual(numbers, [0, 1, 2, 3, 4]); | assert.deepEqual(numbers, [0, 1, 2, 3, 4]); | ||||
})); | })); | ||||
it("returns correct numbers for collection-not(less-than(2))", () => | it("returns correct numbers for collection-not(less-than(2))", () => | ||||
with_running_app(async ({ app, rest_api }) => { | with_running_app(async ({ app, rest_api }) => { | ||||
await setup(app); | await setup(app); | ||||
const numbers = (await rest_api.get( | const numbers = (await rest_api.get( | ||||
"/api/v1/collections/collection-not(less-than(2))?format%5Bnumber%5D=expand" | "/api/v1/collections/collection-not(less-than(2))?format%5Bnumber%5D=expand" | ||||
)).items.map(n => n.body.number.body.number); | )).items.map(n => n.number.number); | ||||
assert.deepEqual(numbers, [2, 3, 4]); | assert.deepEqual(numbers, [2, 3, 4]); | ||||
})); | })); | ||||
it("returns correct numbers for collection-not(less-than(6))", () => | it("returns correct numbers for collection-not(less-than(6))", () => | ||||
with_running_app(async ({ app, rest_api }) => { | with_running_app(async ({ app, rest_api }) => { | ||||
await setup(app); | await setup(app); | ||||
const numbers = (await rest_api.get( | const numbers = (await rest_api.get( | ||||
"/api/v1/collections/collection-not(less-than(6))?format%5Bnumber%5D=expand" | "/api/v1/collections/collection-not(less-than(6))?format%5Bnumber%5D=expand" | ||||
)).items.map(n => n.body.number.body.number); | )).items.map(n => n.number.number); | ||||
assert.deepEqual(numbers, []); | assert.deepEqual(numbers, []); | ||||
})); | })); | ||||
}); | }); |