Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/tasks_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export default class TasksController {

// 2. Check if team belongs to the same event as the task
if (team.eventId !== task.eventId)
return response.badRequest({ message: 'Team does not belong to the same event as the task' })
return response.forbidden({ message: 'Team does not belong to the same event as the task' })

// 4. Check if registration is open for the task
const now = DateTime.now()
Expand Down
5 changes: 5 additions & 0 deletions database/seeders/0_user_seeder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export default class extends BaseSeeder {
email: 'user@local.host',
password: 'userpassword',
permissions: UserGuard.build(),
}, {
nickname: 'user2',
email: 'user2@local.host',
password: 'user2password',
permissions: UserGuard.build(),
}])
}
}
9 changes: 9 additions & 0 deletions database/seeders/1_event_seeder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ export default class extends BaseSeeder {
minTeamSize: 1,
maxTeamSize: 5,
},
{
slug: 'team-size-event',
title: 'Event with team size limits.',
description: '#This is a test event created by EventSeeder. \n This event has team size limits of 2 to 3 members.',
accessCode: null,
status: 'ACTIVE',
minTeamSize: 2,
maxTeamSize: 3,
},
])

for (const event of createdEvents)
Expand Down
9 changes: 9 additions & 0 deletions database/seeders/2_team_seeder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export default class extends BaseSeeder {
if (!user)
throw new Error('User not found. Please run UserSeeder first.')

const user2 = await User.findBy('nickname', 'user2')
if (!user2)
throw new Error('Normal user not found. Please run UserSeeder first.')

const hackathonEvent = await Event.findByUuidOrSlug('hackathon-tasks')
if (!hackathonEvent)
throw new Error('Hackathon event not found. Please run EventSeeder first.')
Expand All @@ -50,5 +54,10 @@ export default class extends BaseSeeder {
userId: user.id,
permissions: TeamMemberGuard.allPermissions(), // User is a team admin
})

await hackathonTeam.related('members').create({
userId: user2.id,
permissions: TeamMemberGuard.build(), // User is NOT a team admin
})
}
}
50 changes: 49 additions & 1 deletion database/seeders/3_task_seeder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export default class extends BaseSeeder {
const hackathonEvent = await Event.findBy('slug', 'hackathon-tasks')
if (!hackathonEvent)
throw new Error('Hackathon event not found. Please run EventSeeder first.')


const teamSizeEvent = await Event.findBy('slug', 'team-size-event')
if (!teamSizeEvent)
throw new Error('Team size event not found. Please run EventSeeder first.')

const tasks = await Task.createMany([
{
Expand Down Expand Up @@ -68,6 +71,51 @@ export default class extends BaseSeeder {
registrationStartAt: DateTime.now(),
registrationEndAt: DateTime.now().plus({ days: 7 }), // 1 week from now
},
{
eventId: hackathonEvent.id,
slug: 'registration-not-started',
title: 'Hackathon Task with Registration Not Started',
description: 'This task has not yet opened for registration.',
taskType: 'HACKATHON',
status: 'ACTIVE',
detailsRevealAt: DateTime.now().plus({ days: 2 }), // Details will be revealed in 2 days
registrationStartAt: DateTime.now().plus({ days: 1 }), // Registration will start in 1 day
registrationEndAt: DateTime.now().plus({ days: 8 }), // Registration will end in 8 days
},
{
eventId: hackathonEvent.id,
slug: 'registration-closed',
title: 'Hackathon Task with Registration Closed',
description: 'This task has closed registration.',
taskType: 'HACKATHON',
status: 'ACTIVE',
detailsRevealAt: DateTime.now().minus({ days: 2 }), // Details were revealed 2 days ago
registrationStartAt: DateTime.now().minus({ days: 8 }), // Registration started 8 days ago
registrationEndAt: DateTime.now().minus({ days: 1 }), // Registration ended 1 day ago
},
{
eventId: hackathonEvent.id,
slug: 'autoregister-task',
title: 'Hackathon Task with Autoregistration',
description: 'This task automatically registers all teams upon registration opening.',
taskType: 'HACKATHON',
status: 'ACTIVE',
detailsRevealAt: DateTime.now().plus({ days: 1 }), // Details will be revealed in 1 day
registrationStartAt: DateTime.now().plus({ days: 1 }), // Registration will start in 1 day
registrationEndAt: DateTime.now().plus({ days: 7 }), // Registration will end in 7 days
autoregister: true,
},
{
eventId: teamSizeEvent.id,
slug: 'team-size-task',
title: 'Task with Team Size Limits',
description: 'This task has team size limits defined by the event.',
taskType: 'HACKATHON',
status: 'ACTIVE',
detailsRevealAt: DateTime.now().plus({ days: 1 }), // Details will be revealed in 1 day
registrationStartAt: DateTime.now(),
registrationEndAt: DateTime.now().plus({ days: 7 }), // 1 week from now
},
])

for (const task of tasks)
Expand Down
12 changes: 6 additions & 6 deletions tests/functional/auth/register.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ test.group('Auth register', (group) => {

test('registers a new user successfully', async ({ client, assert }) => {
const response = await client.post('/auth/register').json({
nickname: 'user2',
email: 'user2@local.host',
nickname: 'newuser',
email: 'newuser@local.host',
password: 'password123',
password_confirmation: 'password123',
})

response.assertStatus(201)
assert.equal(response.body().message, 'Registration successful')
assert.exists(response.body().user.id)
assert.equal(response.body().user.email, 'user2@local.host')
assert.equal(response.body().user.email, 'newuser@local.host')
})

test('fails when password is not strong enough', async ({ client }) => {
const response = await client.post('/auth/register').json({
nickname: 'mysecondaccount',
email: 'user2@local.host',
email: 'newuser@local.host',
password: 'notsafe',
password_confirmation: 'notsafe',
})
Expand Down Expand Up @@ -74,8 +74,8 @@ test.group('Auth register', (group) => {

test('fails when passwords do not match', async ({ client }) => {
const response = await client.post('/auth/register').json({
nickname: 'user2',
email: 'user2@local.host',
nickname: 'newuser',
email: 'newuser@local.host',
password: 'password123',
password_confirmation: 'password456',
})
Expand Down
Loading