Refactor part 2
This commit is contained in:
parent
e21a807fb3
commit
80196b732a
9 changed files with 78 additions and 25 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "tether",
|
||||
"version": "0.3.4",
|
||||
"version": "0.3.6",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "tether",
|
||||
"version": "0.3.4",
|
||||
"version": "0.3.6",
|
||||
"license": "GPL-3.0-only",
|
||||
"dependencies": {
|
||||
"@fastify/cookie": "^11.0.2",
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ const postCreateCommunity = async (
|
|||
name: community.name,
|
||||
description: community.description,
|
||||
ownerId: community.ownerId,
|
||||
creationDate: community.creationDate.getTime(),
|
||||
} as IPostCreateCommunityResponseSuccess;
|
||||
};
|
||||
|
||||
|
|
@ -116,6 +117,8 @@ const patchCommunity = async (request: FastifyRequest, reply: FastifyReply) => {
|
|||
id: community.id,
|
||||
name: community.name,
|
||||
description: community.description,
|
||||
ownerId: community.ownerId,
|
||||
creationDate: community.creationDate.getTime(),
|
||||
} as IPatchCommunityResponseSuccess;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,6 @@
|
|||
import type { API_ERROR } from "../errors.js";
|
||||
|
||||
interface IGetInviteParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
interface IGetInviteResponseError {
|
||||
id: string;
|
||||
error: API_ERROR;
|
||||
}
|
||||
|
||||
interface IGetInviteResponseSuccess {
|
||||
interface IInvite {
|
||||
id: string;
|
||||
communityId: string;
|
||||
valid: boolean;
|
||||
|
|
@ -21,6 +12,17 @@ interface IGetInviteResponseSuccess {
|
|||
expirationDate: number;
|
||||
}
|
||||
|
||||
interface IGetInviteParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
interface IGetInviteResponseError {
|
||||
id: string;
|
||||
error: API_ERROR;
|
||||
}
|
||||
|
||||
interface IGetInviteResponseSuccess extends IInvite {}
|
||||
|
||||
interface IDeleteInviteParams {
|
||||
id: string;
|
||||
}
|
||||
|
|
@ -53,6 +55,7 @@ interface IPostAcceptDeleteInviteResponseSuccess {
|
|||
}
|
||||
|
||||
export {
|
||||
type IInvite,
|
||||
type IGetInviteParams,
|
||||
type IGetInviteResponseError,
|
||||
type IGetInviteResponseSuccess,
|
||||
|
|
|
|||
|
|
@ -55,7 +55,9 @@ const getRole = async (request: FastifyRequest, reply: FastifyReply) => {
|
|||
return {
|
||||
id: role.id,
|
||||
name: role.name,
|
||||
description: role.description,
|
||||
communityId: role.communityId,
|
||||
permissions: role.permissions,
|
||||
creationDate: role.creationDate.getTime(),
|
||||
} as IGetRoleResponseSuccess;
|
||||
};
|
||||
|
|
@ -75,7 +77,10 @@ const postCreateRole = async (request: FastifyRequest, reply: FastifyReply) => {
|
|||
return {
|
||||
id: role.id,
|
||||
name: role.name,
|
||||
description: role.description,
|
||||
communityId: role.communityId,
|
||||
permissions: role.permissions,
|
||||
creationDate: role.creationDate.getTime(),
|
||||
} as IPostCreateRoleResponseSuccess;
|
||||
};
|
||||
|
||||
|
|
@ -103,8 +108,10 @@ const patchRole = async (request: FastifyRequest, reply: FastifyReply) => {
|
|||
return {
|
||||
id: role.id,
|
||||
name: role.name,
|
||||
description: role.description,
|
||||
communityId: role.communityId,
|
||||
permissions: role.permissions,
|
||||
creationDate: role.creationDate.getTime(),
|
||||
} as IPatchRoleResponseSuccess;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -78,7 +78,12 @@ interface IPostAssignRoleResponseError {
|
|||
error: API_ERROR;
|
||||
}
|
||||
|
||||
interface IPostAssignRoleResponseSuccess extends IRole {}
|
||||
interface IPostAssignRoleResponseSuccess {
|
||||
id: string;
|
||||
name: string;
|
||||
communityId: string;
|
||||
userId: string;
|
||||
}
|
||||
|
||||
interface IPostUnassignRoleParams {
|
||||
id: string;
|
||||
|
|
@ -93,7 +98,12 @@ interface IPostUnassignRoleResponseError {
|
|||
error: API_ERROR;
|
||||
}
|
||||
|
||||
interface IPostUnassignRoleResponseSuccess extends IRole {}
|
||||
interface IPostUnassignRoleResponseSuccess {
|
||||
id: string;
|
||||
name: string;
|
||||
communityId: string;
|
||||
userId: string;
|
||||
}
|
||||
|
||||
export {
|
||||
type IRole,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
import type { API_ERROR } from "../errors.js";
|
||||
|
||||
interface ISession {
|
||||
id: string;
|
||||
userId: string;
|
||||
creationDate: number;
|
||||
}
|
||||
|
||||
interface IGetSessionParams {
|
||||
id: string;
|
||||
}
|
||||
|
|
@ -9,11 +15,7 @@ interface IGetSessionResponseError {
|
|||
error: API_ERROR;
|
||||
}
|
||||
|
||||
interface IGetSessionResponseSuccess {
|
||||
id: string;
|
||||
userId: string;
|
||||
creationDate: number;
|
||||
}
|
||||
interface IGetSessionResponseSuccess extends ISession {}
|
||||
|
||||
interface IDeleteSessionParams {
|
||||
id: string;
|
||||
|
|
@ -30,6 +32,7 @@ interface IDeleteSessionResponseSuccess {
|
|||
}
|
||||
|
||||
export {
|
||||
type ISession,
|
||||
type IGetSessionParams,
|
||||
type IGetSessionResponseError,
|
||||
type IGetSessionResponseSuccess,
|
||||
|
|
|
|||
|
|
@ -98,6 +98,8 @@ const postCreateUser = async (request: FastifyRequest, reply: FastifyReply) => {
|
|||
email: user.email,
|
||||
description: user.description,
|
||||
admin: user.admin,
|
||||
registerDate: user.registerDate.getTime(),
|
||||
lastLogin: user.lastLogin?.getTime() ?? 0,
|
||||
} as IPostCreateUserResponseSuccess;
|
||||
};
|
||||
|
||||
|
|
@ -124,8 +126,12 @@ const patchUser = async (request: FastifyRequest, reply: FastifyReply) => {
|
|||
|
||||
return {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
description: user.description,
|
||||
admin: user.admin,
|
||||
registerDate: user.registerDate.getTime(),
|
||||
lastLogin: user.lastLogin?.getTime() ?? 0,
|
||||
} as IPatchUserResponseSuccess;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -91,6 +91,10 @@ test("can get user", async () => {
|
|||
assert.equal(response.id, state.userId);
|
||||
assert.equal(response.username, state.username);
|
||||
assert.equal(response.email, state.email);
|
||||
assert.equal(response.description, null);
|
||||
assert.equal(response.admin, false);
|
||||
assert.notEqual(response.registerDate, undefined);
|
||||
assert.notEqual(response.lastLogin, undefined);
|
||||
});
|
||||
|
||||
test("can modify user", async () => {
|
||||
|
|
@ -113,6 +117,9 @@ test("can modify user", async () => {
|
|||
assert.equal(responseGet.id, state.userId);
|
||||
assert.equal(responseGet.email, state.email);
|
||||
assert.equal(responseGet.description, state.description);
|
||||
assert.equal(responseGet.admin, false);
|
||||
assert.notEqual(responseGet.registerDate, undefined);
|
||||
assert.notEqual(responseGet.lastLogin, undefined);
|
||||
});
|
||||
|
||||
test("can get user sessions", async () => {
|
||||
|
|
|
|||
|
|
@ -71,11 +71,13 @@ test("can create community", async () => {
|
|||
assert.equal(responseCreate.name, state.communityName);
|
||||
assert.equal(responseCreate.description, state.communityDescription);
|
||||
assert.equal(responseCreate.ownerId, state.userId1);
|
||||
assert.notEqual(responseCreate.creationDate, undefined);
|
||||
|
||||
const responseGet = await apiGet(`community/${state.communityId}`);
|
||||
assert.equal(responseGet.name, state.communityName);
|
||||
assert.equal(responseGet.description, state.communityDescription);
|
||||
assert.equal(responseGet.ownerId, state.userId1);
|
||||
assert.notEqual(responseGet.creationDate, undefined);
|
||||
});
|
||||
|
||||
test("shouldn't be able to create invite", async () => {
|
||||
|
|
@ -133,7 +135,7 @@ test("can accept invite", async () => {
|
|||
|
||||
assert.equal(responseGet.id, state.communityId);
|
||||
assert.equal(responseGet.name, state.communityName);
|
||||
assert.equal(responseGet.members.length === 2, true);
|
||||
assert.equal(responseGet.members.length, 2);
|
||||
});
|
||||
|
||||
test("can get user communities", async () => {
|
||||
|
|
@ -143,7 +145,7 @@ test("can get user communities", async () => {
|
|||
);
|
||||
|
||||
assert.equal(response.id, state.userId2);
|
||||
assert.equal(response.communities.length === 1, true);
|
||||
assert.equal(response.communities.length, 1);
|
||||
assert.equal(response.communities[0].id, state.communityId);
|
||||
assert.equal(response.communities[0].name, state.communityName);
|
||||
assert.equal(
|
||||
|
|
@ -193,11 +195,13 @@ test("shouldn't be able to get roles", async () => {
|
|||
|
||||
test("can create channel", async () => {
|
||||
state.channelName = "Test Channel";
|
||||
state.channelDescription = "Test Channel Desc";
|
||||
|
||||
const response = await apiPost(
|
||||
`channel`,
|
||||
{
|
||||
name: state.channelName,
|
||||
description: state.channelDescription,
|
||||
communityId: state.communityId,
|
||||
},
|
||||
state.token1,
|
||||
|
|
@ -205,18 +209,22 @@ test("can create channel", async () => {
|
|||
|
||||
assert.equal(validate(response.id), true);
|
||||
assert.equal(response.name, state.channelName);
|
||||
assert.equal(response.description, state.channelDescription);
|
||||
assert.equal(response.communityId, state.communityId);
|
||||
assert.notEqual(response.creationDate, undefined);
|
||||
|
||||
state.channelId = response.id;
|
||||
});
|
||||
|
||||
test("can create role", async () => {
|
||||
state.roleName = "Test Role";
|
||||
state.roleDescription = "Test Role Desc";
|
||||
|
||||
const response = await apiPost(
|
||||
`role`,
|
||||
{
|
||||
name: state.roleName,
|
||||
description: state.roleDescription,
|
||||
communityId: state.communityId,
|
||||
permissions: ["MEMBERS_READ", "CHANNELS_READ", "ROLES_READ"],
|
||||
},
|
||||
|
|
@ -225,7 +233,10 @@ test("can create role", async () => {
|
|||
|
||||
assert.equal(validate(response.id), true);
|
||||
assert.equal(response.name, state.roleName);
|
||||
assert.equal(response.description, state.roleDescription);
|
||||
assert.equal(response.communityId, state.communityId);
|
||||
assert.equal(response.permissions.length, 3);
|
||||
assert.notEqual(response.creationDate, undefined);
|
||||
|
||||
state.roleId = response.id;
|
||||
});
|
||||
|
|
@ -253,7 +264,7 @@ test("can get members", async () => {
|
|||
|
||||
assert.equal(response.id, state.communityId);
|
||||
assert.equal(response.name, state.communityName);
|
||||
assert.equal(response.members.length === 2, true);
|
||||
assert.equal(response.members.length, 2);
|
||||
});
|
||||
|
||||
test("can get channels", async () => {
|
||||
|
|
@ -264,7 +275,7 @@ test("can get channels", async () => {
|
|||
|
||||
assert.equal(response.id, state.communityId);
|
||||
assert.equal(response.name, state.communityName);
|
||||
assert.equal(response.channels.length === 1, true);
|
||||
assert.equal(response.channels.length, 1);
|
||||
});
|
||||
|
||||
test("can get roles", async () => {
|
||||
|
|
@ -275,7 +286,7 @@ test("can get roles", async () => {
|
|||
|
||||
assert.equal(response.id, state.communityId);
|
||||
assert.equal(response.name, state.communityName);
|
||||
assert.equal(response.roles.length === 1, true);
|
||||
assert.equal(response.roles.length, 1);
|
||||
});
|
||||
|
||||
test("can get permissions", async () => {
|
||||
|
|
@ -283,8 +294,11 @@ test("can get permissions", async () => {
|
|||
|
||||
assert.equal(response.id, state.roleId);
|
||||
assert.equal(response.name, state.roleName);
|
||||
assert.equal(response.description, state.roleDescription);
|
||||
assert.equal(response.communityId, state.communityId);
|
||||
assert.equal(response.permissions.length === 3, true);
|
||||
assert.equal(response.permissions.length, 3);
|
||||
assert.equal(response.permissions[1], "CHANNELS_READ");
|
||||
assert.notEqual(response.creationDate, undefined);
|
||||
});
|
||||
|
||||
test("can unassign role from user", async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue