Skip to content

Commit

Permalink
➡️ merge pull request #53 from devsoc-unsw/feature/settingsSocietyEvents
Browse files Browse the repository at this point in the history
add terrible settings user societies page, and create society page
  • Loading branch information
lachlanshoesmith authored Dec 14, 2024
2 parents 95d3d8c + 59ea8a7 commit e1c9e45
Show file tree
Hide file tree
Showing 20 changed files with 1,343 additions and 1,129 deletions.
2 changes: 1 addition & 1 deletion backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ app.get('/society/events', async (req, res: Response) => {
});

app.post(
'/society/create',
'/society',
async (req: TypedRequest<CreateSocietyBody>, res: Response) => {
const society = req.body;
if (!society.name) {
Expand Down
174 changes: 87 additions & 87 deletions backend/tests/attendEvent.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { expect, test, vi, describe } from "vitest"; // 👈🏻 Added the `vi` import
import prisma from "../src/prisma";
import request from "supertest";
import app from "../src/index";

describe("POST /user/event (attend) endpoint", () => {
test("Attend successful", async () => {
const { status, body } = await request(app).post("/auth/register").send({
username: "shinjisatoo",
password: "testpassword",
email: "[email protected]",
import { expect, test, vi, describe } from 'vitest'; // 👈🏻 Added the `vi` import
import prisma from '../src/prisma';
import request from 'supertest';
import app from '../src/index';

describe('POST /user/event (attend) endpoint', () => {
test('Attend successful', async () => {
const { status, body } = await request(app).post('/auth/register').send({
username: 'shinjisatoo',
password: 'testpassword',
email: '[email protected]',
});

const newUser = await prisma.user.findFirst({
Expand All @@ -21,52 +21,52 @@ describe("POST /user/event (attend) endpoint", () => {
expect(status).toBe(201);
expect(newUser).not.toBeNull();

const loginres = await request(app).post("/auth/login").send({
username: "shinjisatoo",
password: "testpassword",
const loginres = await request(app).post('/auth/login').send({
username: 'shinjisatoo',
password: 'testpassword',
});
let sessionID = loginres.headers["set-cookie"];
let sessionID = loginres.headers['set-cookie'];

const societyRes = await request(app)
.post("/society/create")
.set("Cookie", sessionID)
.post('/society')
.set('Cookie', sessionID)
.send({
name: "Rizzsoc",
name: 'Rizzsoc',
});

const socId = societyRes.body.id;
expect(societyRes.status).toBe(200);
const start = new Date();

const eventRes = await request(app)
.post("/event")
.set("Cookie", sessionID)
.post('/event')
.set('Cookie', sessionID)
.send({
banner:
"https://img-cdn.inc.com/image/upload/f_webp,q_auto,c_fit/images/panoramic/Island-Entertainment-viral-tiktok-inc_539684_hnvnix.jpg",
name: "tiktokrizzparty",
'https://img-cdn.inc.com/image/upload/f_webp,q_auto,c_fit/images/panoramic/Island-Entertainment-viral-tiktok-inc_539684_hnvnix.jpg',
name: 'tiktokrizzparty',
startDateTime: new Date(),
endDateTime: new Date(start.getTime() + 86400000),
location: "tampa, florida",
description: "fein! fein! fein! fein! fein so good she honor roll",
location: 'tampa, florida',
description: 'fein! fein! fein! fein! fein so good she honor roll',
societyId: socId,
});

const attendRes = await request(app)
.post("/user/event")
.set("Cookie", sessionID)
.post('/user/event')
.set('Cookie', sessionID)
.send({
eventId: eventRes.body.numId,
});

expect(attendRes.status).toBe(200);
});

test("Event invalid", async () => {
const { status, body } = await request(app).post("/auth/register").send({
username: "shinjisatoo",
password: "testpassword",
email: "[email protected]",
test('Event invalid', async () => {
const { status, body } = await request(app).post('/auth/register').send({
username: 'shinjisatoo',
password: 'testpassword',
email: '[email protected]',
});

const newUser = await prisma.user.findFirst({
Expand All @@ -79,17 +79,17 @@ describe("POST /user/event (attend) endpoint", () => {
expect(status).toBe(201);
expect(newUser).not.toBeNull();

const loginres = await request(app).post("/auth/login").send({
username: "shinjisatoo",
password: "testpassword",
const loginres = await request(app).post('/auth/login').send({
username: 'shinjisatoo',
password: 'testpassword',
});
let sessionID = loginres.headers["set-cookie"];
let sessionID = loginres.headers['set-cookie'];

const societyRes = await request(app)
.post("/society/create")
.set("Cookie", sessionID)
.post('/society')
.set('Cookie', sessionID)
.send({
name: "Rizzsoc",
name: 'Rizzsoc',
userId: newUser.id,
});

Expand All @@ -98,22 +98,22 @@ describe("POST /user/event (attend) endpoint", () => {
const start = new Date();

const eventRes = await request(app)
.post("/event")
.set("Cookie", sessionID)
.post('/event')
.set('Cookie', sessionID)
.send({
banner:
"https://img-cdn.inc.com/image/upload/f_webp,q_auto,c_fit/images/panoramic/Island-Entertainment-viral-tiktok-inc_539684_hnvnix.jpg",
name: "tiktokrizzparty",
'https://img-cdn.inc.com/image/upload/f_webp,q_auto,c_fit/images/panoramic/Island-Entertainment-viral-tiktok-inc_539684_hnvnix.jpg',
name: 'tiktokrizzparty',
startDateTime: new Date(),
endDateTime: new Date(start.getTime() + 86400000),
location: "tampa, florida",
description: "fein! fein! fein! fein! fein so good she honor roll",
location: 'tampa, florida',
description: 'fein! fein! fein! fein! fein so good she honor roll',
societyId: socId,
});

const attendRes = await request(app)
.post("/user/event")
.set("Cookie", sessionID)
.post('/user/event')
.set('Cookie', sessionID)
.send({
eventId: -123,
});
Expand All @@ -122,12 +122,12 @@ describe("POST /user/event (attend) endpoint", () => {
});
});

describe("/unattend endpoint", () => {
test("Unattend successful", async () => {
const { status, body } = await request(app).post("/auth/register").send({
username: "shinjisatoo",
password: "testpassword",
email: "[email protected]",
describe('/unattend endpoint', () => {
test('Unattend successful', async () => {
const { status, body } = await request(app).post('/auth/register').send({
username: 'shinjisatoo',
password: 'testpassword',
email: '[email protected]',
});

const newUser = await prisma.user.findFirst({
Expand All @@ -140,17 +140,17 @@ describe("/unattend endpoint", () => {
expect(status).toBe(201);
expect(newUser).not.toBeNull();

const loginres = await request(app).post("/auth/login").send({
username: "shinjisatoo",
password: "testpassword",
const loginres = await request(app).post('/auth/login').send({
username: 'shinjisatoo',
password: 'testpassword',
});
let sessionID = loginres.headers["set-cookie"];
let sessionID = loginres.headers['set-cookie'];

const societyRes = await request(app)
.post("/society/create")
.set("Cookie", sessionID)
.post('/society')
.set('Cookie', sessionID)
.send({
name: "Rizzsoc",
name: 'Rizzsoc',
userId: newUser.id,
});

Expand All @@ -159,34 +159,34 @@ describe("/unattend endpoint", () => {
const start = new Date();

const eventRes = await request(app)
.post("/event")
.set("Cookie", sessionID)
.post('/event')
.set('Cookie', sessionID)
.send({
banner:
"https://img-cdn.inc.com/image/upload/f_webp,q_auto,c_fit/images/panoramic/Island-Entertainment-viral-tiktok-inc_539684_hnvnix.jpg",
name: "tiktokrizzparty",
'https://img-cdn.inc.com/image/upload/f_webp,q_auto,c_fit/images/panoramic/Island-Entertainment-viral-tiktok-inc_539684_hnvnix.jpg',
name: 'tiktokrizzparty',
startDateTime: new Date(),
endDateTime: new Date(start.getTime() + 86400000),
location: "tampa, florida",
description: "fein! fein! fein! fein! fein so good she honor roll",
location: 'tampa, florida',
description: 'fein! fein! fein! fein! fein so good she honor roll',
societyId: socId,
});

const attendRes = await request(app)
.delete("/user/event")
.set("Cookie", sessionID)
.delete('/user/event')
.set('Cookie', sessionID)
.send({
eventId: eventRes.body.numId,
});

expect(attendRes.status).toBe(200);
});

test("Event invalid", async () => {
const { status, body } = await request(app).post("/auth/register").send({
username: "shinjisatoo",
password: "testpassword",
email: "[email protected]",
test('Event invalid', async () => {
const { status, body } = await request(app).post('/auth/register').send({
username: 'shinjisatoo',
password: 'testpassword',
email: '[email protected]',
});

const newUser = await prisma.user.findFirst({
Expand All @@ -199,17 +199,17 @@ describe("/unattend endpoint", () => {
expect(status).toBe(201);
expect(newUser).not.toBeNull();

const loginres = await request(app).post("/auth/login").send({
username: "shinjisatoo",
password: "testpassword",
const loginres = await request(app).post('/auth/login').send({
username: 'shinjisatoo',
password: 'testpassword',
});
let sessionID = loginres.headers["set-cookie"];
let sessionID = loginres.headers['set-cookie'];

const societyRes = await request(app)
.post("/society/create")
.set("Cookie", sessionID)
.post('/society')
.set('Cookie', sessionID)
.send({
name: "Rizzsoc",
name: 'Rizzsoc',
userId: newUser.id,
});

Expand All @@ -218,22 +218,22 @@ describe("/unattend endpoint", () => {
const start = new Date();

const eventRes = await request(app)
.post("/event")
.set("Cookie", sessionID)
.post('/event')
.set('Cookie', sessionID)
.send({
banner:
"https://img-cdn.inc.com/image/upload/f_webp,q_auto,c_fit/images/panoramic/Island-Entertainment-viral-tiktok-inc_539684_hnvnix.jpg",
name: "tiktokrizzparty",
'https://img-cdn.inc.com/image/upload/f_webp,q_auto,c_fit/images/panoramic/Island-Entertainment-viral-tiktok-inc_539684_hnvnix.jpg',
name: 'tiktokrizzparty',
startDateTime: new Date(),
endDateTime: new Date(start.getTime() + 86400000),
location: "tampa, florida",
description: "fein! fein! fein! fein! fein so good she honor roll",
location: 'tampa, florida',
description: 'fein! fein! fein! fein! fein so good she honor roll',
societyId: socId,
});

const attendRes = await request(app)
.delete("/user/event")
.set("Cookie", sessionID)
.delete('/user/event')
.set('Cookie', sessionID)
.send({
eventId: -123,
});
Expand Down
Loading

0 comments on commit e1c9e45

Please sign in to comment.