tests Room Owner
This commit is contained in:
parent
4128155189
commit
e640d325f1
8 changed files with 236 additions and 35 deletions
|
@ -1,3 +1,4 @@
|
||||||
export * from "./acts/login.js";
|
export * from "./acts/login.js";
|
||||||
export * from "./acts/client.js"
|
export * from "./acts/client.js"
|
||||||
export * from "./acts/admin.js"
|
export * from "./acts/admin.js"
|
||||||
|
export * from "./acts/rooms.js"
|
|
@ -99,12 +99,13 @@ export const createRoom = {
|
||||||
server: "string", // Unused/Ignored at the Moment
|
server: "string", // Unused/Ignored at the Moment
|
||||||
title: "string-255",
|
title: "string-255",
|
||||||
description: "string-255",
|
description: "string-255",
|
||||||
isPublic: "number",
|
public: "number",
|
||||||
icon: "string-255"
|
icon: "string-255"
|
||||||
},
|
},
|
||||||
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
||||||
if (!await canCreateRoom(client.accID))
|
if (!await canCreateRoom(client.accID))
|
||||||
return void aws("error", "limit");
|
return void aws("error", "limit");
|
||||||
|
try {
|
||||||
let req = await insert(
|
let req = await insert(
|
||||||
rooms.name,
|
rooms.name,
|
||||||
rooms.owner,
|
rooms.owner,
|
||||||
|
@ -115,12 +116,11 @@ export const createRoom = {
|
||||||
).add(
|
).add(
|
||||||
data.room,
|
data.room,
|
||||||
client.accID,
|
client.accID,
|
||||||
data.isPublic,
|
data.public,
|
||||||
data.title,
|
data.title,
|
||||||
data.description,
|
data.description,
|
||||||
data.icon
|
data.icon
|
||||||
).query(db);
|
).query(db);
|
||||||
|
|
||||||
if (req.affectedRows > 0) {
|
if (req.affectedRows > 0) {
|
||||||
await insert(roomMembers.roomID, roomMembers.name, roomMembers.server, roomMembers.admin)
|
await insert(roomMembers.roomID, roomMembers.name, roomMembers.server, roomMembers.admin)
|
||||||
.add(req.insertId, client.name, "local", true)
|
.add(req.insertId, client.name, "local", true)
|
||||||
|
@ -129,6 +129,10 @@ export const createRoom = {
|
||||||
} else {
|
} else {
|
||||||
aws("error", "existence");
|
aws("error", "existence");
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
client.suspect();
|
||||||
|
aws("error", "existence");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -158,7 +162,6 @@ export const listPublicRooms = {
|
||||||
right: PERMISSIONS.CAN_USE_API,
|
right: PERMISSIONS.CAN_USE_API,
|
||||||
data: {},
|
data: {},
|
||||||
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
||||||
|
|
||||||
let req = await select([
|
let req = await select([
|
||||||
rooms.name,
|
rooms.name,
|
||||||
rooms.public,
|
rooms.public,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { alias, and, eq, exists, innerJoinOn, insert, le, minus, naturalJoin, not, or, remove, select, update } from "dblang";
|
import { alias, and, eq, exists, innerJoinOn, innerJoinUsing, insert, le, minus, naturalJoin, not, or, remove, select, update } from "dblang";
|
||||||
import { ROOM_RIGHTS } from "../../server/permissions.js";
|
import { ROOM_RIGHTS } from "../../server/permissions.js";
|
||||||
import { accounts, db, roomMembers, roomOTAs, rooms } from "../../sys/db.js";
|
import { accounts, db, roomMembers, roomOTAs, rooms } from "../../sys/db.js";
|
||||||
import { uts } from "../../sys/tools.js";
|
import { uts } from "../../sys/tools.js";
|
||||||
|
@ -22,7 +22,7 @@ export const listLocalRooms: Act = {
|
||||||
rooms.title,
|
rooms.title,
|
||||||
rooms.description,
|
rooms.description,
|
||||||
rooms.icon
|
rooms.icon
|
||||||
], naturalJoin(rooms, roomMembers))
|
], innerJoinUsing(rooms, roomMembers, rooms.roomID, roomMembers.roomID))
|
||||||
.where(and(
|
.where(and(
|
||||||
eq(roomMembers.name, client.name),
|
eq(roomMembers.name, client.name),
|
||||||
eq(roomMembers.server, client.state == STATE.client ? "local" : client.server.tag)
|
eq(roomMembers.server, client.state == STATE.client ? "local" : client.server.tag)
|
||||||
|
|
|
@ -22,6 +22,6 @@ database=outbag
|
||||||
|
|
||||||
[Settings]
|
[Settings]
|
||||||
maxUsers=2
|
maxUsers=2
|
||||||
defaultMaxRooms=3
|
defaultMaxRooms=2
|
||||||
defaultMaxRoomSize=10
|
defaultMaxRoomSize=10
|
||||||
defaultMaxUsersPerRoom=2
|
defaultMaxUsersPerRoom=2
|
||||||
|
|
|
@ -31,7 +31,10 @@ function shallowEqual(object1, object2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (let key of keys1) {
|
for (let key of keys1) {
|
||||||
if (object1[key] != null && object1[key] != object2[key]) {
|
if (typeof object1[key] == "object" && object1[key] != null) {
|
||||||
|
if(typeof object2[key] != "object") return false;
|
||||||
|
if(!shallowEqual(object1[key], object2[key])) return false;
|
||||||
|
} else if (object1[key] != null && object1[key] != object2[key]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,10 @@ let name2 = "testUser2";
|
||||||
let name3 = "testUser3";
|
let name3 = "testUser3";
|
||||||
let accountKey = "123456789";
|
let accountKey = "123456789";
|
||||||
|
|
||||||
|
let room1 = "r1";
|
||||||
|
let room2 = "r2";
|
||||||
|
let room3 = "r3";
|
||||||
|
|
||||||
let { privateKey, publicKey } = await generateSigningKey();
|
let { privateKey, publicKey } = await generateSigningKey();
|
||||||
|
|
||||||
const list = [
|
const list = [
|
||||||
|
@ -96,7 +100,7 @@ const list = [
|
||||||
rights: PERMISSIONS.ALL,
|
rights: PERMISSIONS.ALL,
|
||||||
name: name1,
|
name: name1,
|
||||||
viewable: true,
|
viewable: true,
|
||||||
maxRooms: 3,
|
maxRooms: 2,
|
||||||
maxRoomSize: 10,
|
maxRoomSize: 10,
|
||||||
maxUsersPerRoom: 2,
|
maxUsersPerRoom: 2,
|
||||||
});
|
});
|
||||||
|
@ -106,7 +110,7 @@ const list = [
|
||||||
rights: PERMISSIONS.DEFAULT,
|
rights: PERMISSIONS.DEFAULT,
|
||||||
name: name2,
|
name: name2,
|
||||||
viewable: true,
|
viewable: true,
|
||||||
maxRooms: 3,
|
maxRooms: 2,
|
||||||
maxRoomSize: 10,
|
maxRoomSize: 10,
|
||||||
maxUsersPerRoom: 2,
|
maxUsersPerRoom: 2,
|
||||||
});
|
});
|
||||||
|
@ -134,6 +138,104 @@ const list = [
|
||||||
server: "localhost:7224",
|
server: "localhost:7224",
|
||||||
accountKey: accountKey + "lol"
|
accountKey: accountKey + "lol"
|
||||||
}, "error", "auth");
|
}, "error", "auth");
|
||||||
|
}], ["room Owner", async (req) => {
|
||||||
|
await req({
|
||||||
|
"authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}`
|
||||||
|
}, "createRoom", {
|
||||||
|
room: room1,
|
||||||
|
server: "localhost:7224",
|
||||||
|
title: "Test Room 1",
|
||||||
|
description: "some desc",
|
||||||
|
public: 0,
|
||||||
|
icon: "shopping"
|
||||||
|
}, "ok", "");
|
||||||
|
await req({
|
||||||
|
"authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}`
|
||||||
|
}, "createRoom", {
|
||||||
|
room: room1,
|
||||||
|
server: "localhost:7224",
|
||||||
|
title: "Test Room 1",
|
||||||
|
description: "some desc",
|
||||||
|
public: 0,
|
||||||
|
icon: "shopping"
|
||||||
|
}, "error", "existence");
|
||||||
|
|
||||||
|
await req({
|
||||||
|
"authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}`
|
||||||
|
}, "createRoom", {
|
||||||
|
room: room2,
|
||||||
|
server: "localhost:7224",
|
||||||
|
title: "Test Room 2",
|
||||||
|
description: "some desc 2",
|
||||||
|
public: 1,
|
||||||
|
icon: ""
|
||||||
|
}, "ok", "");
|
||||||
|
await req({
|
||||||
|
"authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}`
|
||||||
|
}, "createRoom", {
|
||||||
|
room: room3,
|
||||||
|
server: "localhost:7224",
|
||||||
|
title: "Test Room 2",
|
||||||
|
description: "some desc 2",
|
||||||
|
public: 1,
|
||||||
|
icon: ""
|
||||||
|
}, "error", "limit");
|
||||||
|
|
||||||
|
await req({
|
||||||
|
"authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}`
|
||||||
|
}, "listLocalRooms", {}, "ok", [
|
||||||
|
{
|
||||||
|
name: room1,
|
||||||
|
owner: name1,
|
||||||
|
rights: 0b11111,
|
||||||
|
title: "Test Room 1",
|
||||||
|
description: "some desc",
|
||||||
|
public: 0,
|
||||||
|
icon: "shopping"
|
||||||
|
}, {
|
||||||
|
name: room2,
|
||||||
|
owner: name1,
|
||||||
|
rights: 0b11111,
|
||||||
|
title: "Test Room 2",
|
||||||
|
description: "some desc 2",
|
||||||
|
public: 1,
|
||||||
|
icon: ""
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
await req({
|
||||||
|
"authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}`
|
||||||
|
}, "deleteRoom", {
|
||||||
|
room: room2 + "lol",
|
||||||
|
server: "localhost:7224"
|
||||||
|
}, "error", "existence");
|
||||||
|
|
||||||
|
await req({
|
||||||
|
"authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}`
|
||||||
|
}, "deleteRoom", {
|
||||||
|
room: room2,
|
||||||
|
server: "localhost:7224"
|
||||||
|
}, "ok", "");
|
||||||
|
|
||||||
|
await req({
|
||||||
|
"authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}`
|
||||||
|
}, "deleteRoom", {
|
||||||
|
room: room2,
|
||||||
|
server: "localhost:7224"
|
||||||
|
}, "error", "existence");
|
||||||
|
|
||||||
|
await req({
|
||||||
|
"authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}`
|
||||||
|
}, "listLocalRooms", {}, "ok", [
|
||||||
|
{
|
||||||
|
name: room1,
|
||||||
|
owner: name1,
|
||||||
|
rights: 0b11111,
|
||||||
|
title: "Test Room 1",
|
||||||
|
description: "some desc",
|
||||||
|
public: 0,
|
||||||
|
icon: "shopping"
|
||||||
|
}
|
||||||
|
]);
|
||||||
}]
|
}]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,10 @@ let name2 = "testUser2";
|
||||||
let name3 = "testUser3";
|
let name3 = "testUser3";
|
||||||
let accountKey = "123456789";
|
let accountKey = "123456789";
|
||||||
|
|
||||||
|
let room1 = "r1";
|
||||||
|
let room2 = "r2";
|
||||||
|
let room3 = "r3";
|
||||||
|
|
||||||
let { privateKey, publicKey } = await generateSigningKey();
|
let { privateKey, publicKey } = await generateSigningKey();
|
||||||
|
|
||||||
const list = [
|
const list = [
|
||||||
|
@ -86,7 +90,7 @@ const list = [
|
||||||
rights: PERMISSIONS.ALL,
|
rights: PERMISSIONS.ALL,
|
||||||
name: name1,
|
name: name1,
|
||||||
viewable: true,
|
viewable: true,
|
||||||
maxRooms: 3,
|
maxRooms: 2,
|
||||||
maxRoomSize: 10,
|
maxRoomSize: 10,
|
||||||
maxUsersPerRoom: 2,
|
maxUsersPerRoom: 2,
|
||||||
});
|
});
|
||||||
|
@ -100,7 +104,7 @@ const list = [
|
||||||
rights: PERMISSIONS.DEFAULT,
|
rights: PERMISSIONS.DEFAULT,
|
||||||
name: name2,
|
name: name2,
|
||||||
viewable: true,
|
viewable: true,
|
||||||
maxRooms: 3,
|
maxRooms: 2,
|
||||||
maxRoomSize: 10,
|
maxRoomSize: 10,
|
||||||
maxUsersPerRoom: 2,
|
maxUsersPerRoom: 2,
|
||||||
});
|
});
|
||||||
|
@ -132,6 +136,91 @@ const list = [
|
||||||
server: "localhost:7224",
|
server: "localhost:7224",
|
||||||
accountKey: accountKey + "lol"
|
accountKey: accountKey + "lol"
|
||||||
}, "error", "auth");
|
}, "error", "auth");
|
||||||
|
}], ["room Owner", async (handler, req, newHandler) => {
|
||||||
|
await req(handler, "signin", {
|
||||||
|
name: name1,
|
||||||
|
server: "localhost:7224",
|
||||||
|
accountKey
|
||||||
|
}, "ok", "");
|
||||||
|
await req(handler, "createRoom", {
|
||||||
|
room: room1,
|
||||||
|
server: "localhost:7224",
|
||||||
|
title: "Test Room 1",
|
||||||
|
description: "some desc",
|
||||||
|
public: 0,
|
||||||
|
icon: "shopping"
|
||||||
|
}, "ok", "");
|
||||||
|
await req(handler, "createRoom", {
|
||||||
|
room: room1,
|
||||||
|
server: "localhost:7224",
|
||||||
|
title: "Test Room 1",
|
||||||
|
description: "some desc",
|
||||||
|
public: 0,
|
||||||
|
icon: "shopping"
|
||||||
|
}, "error", "existence");
|
||||||
|
|
||||||
|
await req(handler, "createRoom", {
|
||||||
|
room: room2,
|
||||||
|
server: "localhost:7224",
|
||||||
|
title: "Test Room 2",
|
||||||
|
description: "some desc 2",
|
||||||
|
public: 1,
|
||||||
|
icon: ""
|
||||||
|
}, "ok", "");
|
||||||
|
|
||||||
|
await req(handler, "createRoom", {
|
||||||
|
room: room3,
|
||||||
|
server: "localhost:7224",
|
||||||
|
title: "Test Room 2",
|
||||||
|
description: "some desc 2",
|
||||||
|
public: 1,
|
||||||
|
icon: ""
|
||||||
|
}, "error", "limit");
|
||||||
|
|
||||||
|
await req(handler, "listLocalRooms", {}, "ok", [
|
||||||
|
{
|
||||||
|
name: room1,
|
||||||
|
owner: name1,
|
||||||
|
rights: 0b11111,
|
||||||
|
title: "Test Room 1",
|
||||||
|
description: "some desc",
|
||||||
|
public: 0,
|
||||||
|
icon: "shopping"
|
||||||
|
}, {
|
||||||
|
name: room2,
|
||||||
|
owner: name1,
|
||||||
|
rights: 0b11111,
|
||||||
|
title: "Test Room 2",
|
||||||
|
description: "some desc 2",
|
||||||
|
public: 1,
|
||||||
|
icon: ""
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
await req(handler, "deleteRoom", {
|
||||||
|
room: room2 + "lol",
|
||||||
|
server: "localhost:7224"
|
||||||
|
}, "error", "existence");
|
||||||
|
await req(handler, "deleteRoom", {
|
||||||
|
room: room2,
|
||||||
|
server: "localhost:7224"
|
||||||
|
}, "ok", "");
|
||||||
|
await req(handler, "deleteRoom", {
|
||||||
|
room: room2,
|
||||||
|
server: "localhost:7224"
|
||||||
|
}, "error", "existence");
|
||||||
|
await req(handler, "listLocalRooms", {}, "ok", [
|
||||||
|
{
|
||||||
|
name: room1,
|
||||||
|
owner: name1,
|
||||||
|
rights: 0b11111,
|
||||||
|
title: "Test Room 1",
|
||||||
|
description: "some desc",
|
||||||
|
public: 0,
|
||||||
|
icon: "shopping"
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
}]
|
}]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,10 @@ function shallowEqual(object1, object2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (let key of keys1) {
|
for (let key of keys1) {
|
||||||
if (object1[key] != null && object1[key] != object2[key]) {
|
if (typeof object1[key] == "object" && object1[key] != null) {
|
||||||
|
if(typeof object2[key] != "object") return false;
|
||||||
|
if(!shallowEqual(object1[key], object2[key])) return false;
|
||||||
|
} else if (object1[key] != null && object1[key] != object2[key]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,7 +107,7 @@ async function wsTester(url) {
|
||||||
console.log("Testing Act:", act, "with Data:", data);
|
console.log("Testing Act:", act, "with Data:", data);
|
||||||
let resp = await conn.req(act, data);
|
let resp = await conn.req(act, data);
|
||||||
if (resp.state != expState) {
|
if (resp.state != expState) {
|
||||||
console.error(`Expected state: '${expState}', but got: '${resp.state}'`);
|
console.error(`Expected state: '${expState}', but got: '${resp.state}' (Data: ${typeof resp.data == "object" ? JSON.stringify(resp.data) : resp.data})`);
|
||||||
kill();
|
kill();
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue