server OTA tests + fixes
This commit is contained in:
parent
ee6b9f0050
commit
e4054c201c
4 changed files with 66 additions and 13 deletions
|
@ -1,4 +1,4 @@
|
|||
import { eq, insert, le, or, remove, select, update } from "dblang";
|
||||
import { and, eq, geq, insert, le, leq, or, remove, select, update } from "dblang";
|
||||
import { PERMISSIONS } from "../../server/permissions.js";
|
||||
import { sha256 } from "../../sys/crypto.js";
|
||||
import { accounts, db, signupOTA } from "../../sys/db.js";
|
||||
|
@ -116,7 +116,10 @@ export const getOTAs: Act = {
|
|||
await remove(signupOTA)
|
||||
.where(or(
|
||||
eq(signupOTA.usesLeft, 0),
|
||||
le(signupOTA.expires, uts())
|
||||
and(
|
||||
le(signupOTA.expires, uts()),
|
||||
geq(signupOTA.expires, 0)
|
||||
)
|
||||
))
|
||||
.query(db);
|
||||
let req = await select([
|
||||
|
@ -127,7 +130,7 @@ export const getOTAs: Act = {
|
|||
.query(db);
|
||||
aws("ok", req.map(d => ({
|
||||
token: d[signupOTA.token],
|
||||
expires: d[signupOTA.expires],
|
||||
expires: Number(d[signupOTA.expires]),
|
||||
usesLeft: d[signupOTA.usesLeft]
|
||||
})));
|
||||
}
|
||||
|
|
|
@ -400,7 +400,7 @@ export const getItems: Act = {
|
|||
.where(eq(listItems.roomID, roomID))
|
||||
.query(db);
|
||||
let out = req.map(d => {
|
||||
let listItemID = d[listItems.listItemID];
|
||||
let listItemID = Number(d[listItems.listItemID]);
|
||||
let state = d[listItems.state];
|
||||
let title = d[listItems.title];
|
||||
let description = d[listItems.description];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { alias, and, eq, exists, geq, innerJoinOn, innerJoinUsing, insert, le, minus, naturalJoin, not, or, remove, select, update } from "dblang";
|
||||
import { alias, and, eq, exists, ge, geq, innerJoinOn, innerJoinUsing, insert, le, minus, naturalJoin, not, or, remove, select, update } from "dblang";
|
||||
import { checkSelfTag, outbagURLfromTag } from "../../server/outbagURL.js";
|
||||
import { ROOM_RIGHTS } from "../../server/permissions.js";
|
||||
import { accounts, db, remoteRooms, roomMembers, roomOTAs, rooms } from "../../sys/db.js";
|
||||
|
@ -243,9 +243,12 @@ export const joinRoom: Act = {
|
|||
if (await isRoomFull(roomID)) return void aws("error", "limit");
|
||||
// TODO: Make Transaktion when possible
|
||||
await remove(roomOTAs)
|
||||
.where(and(
|
||||
.where(or(
|
||||
eq(roomOTAs.usesLeft, 0),
|
||||
and(
|
||||
le(roomOTAs.expires, uts()),
|
||||
geq(roomOTAs.expires, 0)
|
||||
)
|
||||
))
|
||||
.query(db);
|
||||
let req = await update(roomOTAs)
|
||||
|
@ -355,13 +358,22 @@ export const getRoomOTAs: Act = {
|
|||
}
|
||||
let roomID = await client.isRoomAdmin(data.room, ROOM_RIGHTS.OTA);
|
||||
if (roomID == -1) return void aws("error", "roomAdmin");
|
||||
await remove(roomOTAs)
|
||||
.where(or(
|
||||
eq(roomOTAs.usesLeft, 0),
|
||||
and(
|
||||
le(roomOTAs.expires, uts()),
|
||||
geq(roomOTAs.expires, 0)
|
||||
)
|
||||
))
|
||||
.query(db);
|
||||
let req = await select([roomOTAs.token, roomOTAs.name, roomOTAs.expires, roomOTAs.usesLeft], roomOTAs)
|
||||
.where(eq(roomOTAs.roomID, roomID))
|
||||
.query(db);
|
||||
aws("ok", req.map(d => ({
|
||||
token: d[roomOTAs.token],
|
||||
name: d[roomOTAs.name],
|
||||
expires: d[roomOTAs.expires],
|
||||
expires: Number(d[roomOTAs.expires]),
|
||||
usesLeft: d[roomOTAs.usesLeft],
|
||||
})));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { generateSigningKey, sign } from '../../dist/sys/crypto.js';
|
||||
import { PERMISSIONS } from '../../dist/server/permissions.js';
|
||||
import { uts, wait } from '../../dist/sys/tools.js';
|
||||
|
||||
let name1 = "testUser1";
|
||||
let name2 = "testUser2";
|
||||
|
@ -191,6 +192,43 @@ const list = [
|
|||
maxUsersPerRoom: 2
|
||||
}
|
||||
]);
|
||||
await req({
|
||||
"authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}`
|
||||
}, "addOTA", {
|
||||
token: "12345678",
|
||||
expires: uts() + 1,
|
||||
usesLeft: -1
|
||||
}, "ok", "");
|
||||
await req({
|
||||
"authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}`
|
||||
}, "getOTAs", {}, "ok", [
|
||||
{
|
||||
token: "12345678",
|
||||
expires: null,
|
||||
usesLeft: -1
|
||||
}
|
||||
]);
|
||||
await req({
|
||||
"authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}`
|
||||
}, "addOTA", {
|
||||
token: "abc",
|
||||
expires: -1,
|
||||
usesLeft: -1
|
||||
}, "ok", "");
|
||||
await wait(2000);
|
||||
await req({
|
||||
"authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}`
|
||||
}, "getOTAs", {}, "ok", [{
|
||||
token: "abc",
|
||||
expires: -1,
|
||||
usesLeft: -1
|
||||
}]);
|
||||
await req({
|
||||
"authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}`
|
||||
}, "deleteOTA", { token: "abc" }, "ok", "");
|
||||
await req({
|
||||
"authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}`
|
||||
}, "getOTAs", {}, "ok", []);
|
||||
}], ["room Owner", async (req) => {
|
||||
await req({
|
||||
"authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}`
|
||||
|
|
Loading…
Reference in a new issue