-
Notifications
You must be signed in to change notification settings - Fork 0
39 testing registrations #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0f11f4c
feat: tests for task registrations
InfoTCube 2ccc56a
fix: changed coliding test
InfoTCube 9c45b82
feat: add missing tests to registrations
InfoTCube 21c4486
fix: remove unused import
InfoTCube 70decd5
feat: build member guard with no permissions in team seeder
InfoTCube 68205ff
fix: typo in auth tests
InfoTCube File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests to ensure that: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,214 @@ | ||
| /* | ||
| * ______ __ __ | ||
| * _ __/ ____/___ ____ / /____ _____/ /_ | ||
| * | |/_/ / / __ \/ __ \/ __/ _ \/ ___/ __/ | ||
| * _> </ /___/ /_/ / / / / /_/ __(__ ) /_ | ||
| * /_/|_|\____/\____/_/ /_/\__/\___/____/\__/ | ||
| * Copyright (C) 2026 xContest Team | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see http://www.gnu.org/licenses/. | ||
| * | ||
| */ | ||
|
|
||
| import { TeamFactory } from '#database/factories/team_factory' | ||
| import Task from '#models/task/task' | ||
| import Event from '#models/event/event' | ||
| import testUtils from '@adonisjs/core/services/test_utils' | ||
| import { test } from '@japa/runner' | ||
| import User from '#models/user' | ||
| import Team from '#models/team/team' | ||
| import TaskRegistration from '#models/task/task_registration' | ||
|
|
||
| test.group('Registrations', (group) => { | ||
| group.each.setup(() => testUtils.db().seed()) | ||
| group.each.teardown(() => testUtils.db().truncate()) | ||
|
|
||
| test('Registers a team to a task successfully', async ({ client }) => { | ||
| const event = await Event.findByUuidOrSlug('hackathon-tasks') | ||
| const user = await User.findByOrFail('nickname', 'user') | ||
| const team = await Team.findByOrFail('name', 'User\'s team') | ||
|
|
||
| const task = await Task.query().where('event_id', event.id).firstOrFail() | ||
| const response = await client.post(`/tasks/${task.slug}/registrations`).json({ | ||
| teamId: team.id, | ||
| }).loginAs(user) | ||
|
|
||
| response.assertCreated() | ||
| response.assertBodyContains({ | ||
| teamId: team.id, | ||
| taskId: task.id, | ||
| }) | ||
| }) | ||
|
|
||
| test('Unregisters a team from a task successfully', async ({ client }) => { | ||
| const user = await User.findByOrFail('nickname', 'user') | ||
| const team = await Team.findByOrFail('name', 'User\'s team') | ||
| const registration = await TaskRegistration.query().where('team_id', team.id).firstOrFail() | ||
|
|
||
| const response = await client.delete(`/registrations/${registration.id}`).loginAs(user) | ||
|
|
||
| response.assertNoContent() | ||
| }) | ||
|
|
||
| test('Fails when user is not a member of the team', async ({ client }) => { | ||
| const user = await User.findByOrFail('nickname', 'user') | ||
| const event = await Event.findByUuidOrSlug('hackathon-tasks') | ||
|
|
||
| const team = await TeamFactory.with('members', 1, (member) => member.with('user')) | ||
| .merge({ eventId: event.id }) | ||
| .create() | ||
|
|
||
| const task = await Task.query().where('event_id', event.id).firstOrFail() | ||
| const response = await client.post(`/tasks/${task.slug}/registrations`).json({ | ||
| teamId: team.id, | ||
| }).loginAs(user) | ||
|
|
||
| response.assertForbidden() | ||
| }) | ||
|
|
||
| test('Fails when team is from a different event', async ({ client }) => { | ||
| const event = await Event.findByUuidOrSlug('no-tasks') | ||
| const team = await TeamFactory.with('members', 1, (member) => member.with('user')) | ||
| .merge({ eventId: event.id }) | ||
| .create() | ||
|
|
||
| await team.load('members') | ||
| const member = team.members[0] | ||
| await member.load('user') | ||
|
|
||
| const taskEvent = await Event.findByUuidOrSlug('hackathon-tasks') | ||
| const task = await Task.query().where('event_id', taskEvent.id).firstOrFail() | ||
| const response = await client.post(`/tasks/${task.slug}/registrations`).json({ | ||
| teamId: team.id, | ||
| }).loginAs(member.user) | ||
|
|
||
| response.assertForbidden() | ||
| }) | ||
|
|
||
| test('Fails when registration has not started yet', async ({ client }) => { | ||
| const user = await User.findByOrFail('nickname', 'user') | ||
| const team = await Team.findByOrFail('name', 'User\'s team') | ||
|
|
||
| const task = await Task.findByOrFail('slug', 'registration-not-started') | ||
| const response = await client.post(`/tasks/${task.slug}/registrations`).json({ | ||
| teamId: team.id, | ||
| }).loginAs(user) | ||
|
|
||
| response.assertBadRequest() | ||
| }) | ||
|
|
||
| test('Fails when registration has already ended', async ({ client }) => { | ||
| const user = await User.findByOrFail('nickname', 'user') | ||
| const team = await Team.findByOrFail('name', 'User\'s team') | ||
|
|
||
| const task = await Task.findByOrFail('slug', 'registration-closed') | ||
| const response = await client.post(`/tasks/${task.slug}/registrations`).json({ | ||
| teamId: team.id, | ||
| }).loginAs(user) | ||
|
|
||
| response.assertBadRequest() | ||
| }) | ||
|
|
||
| test('Fails when team size is below the minimum', async ({ client }) => { | ||
| const event = await Event.findByUuidOrSlug('team-size-event') | ||
|
|
||
| const team = await TeamFactory.with('members', 1, (member) => member.with('user')) | ||
| .merge({ eventId: event.id }) | ||
| .create() | ||
|
|
||
| await team.load('members') | ||
| const member = team.members[0] | ||
| await member.load('user') | ||
|
|
||
| const task = await Task.query().where('event_id', event.id).firstOrFail() | ||
| const response = await client.post(`/tasks/${task.slug}/registrations`).json({ | ||
| teamId: team.id, | ||
| }).loginAs(member.user) | ||
|
|
||
| response.assertBadRequest() | ||
| }) | ||
|
|
||
| test('Fails when team size is above the maximum', async ({ client }) => { | ||
| const event = await Event.findByUuidOrSlug('team-size-event') | ||
|
|
||
| const team = await TeamFactory.with('members', 5, (member) => member.with('user')) | ||
| .merge({ eventId: event.id }) | ||
| .create() | ||
|
|
||
| await team.load('members', (query) => query.orderBy('created_at', 'asc')) | ||
| const member = team.members[0] | ||
| await member.load('user') | ||
|
|
||
| const task = await Task.query().where('event_id', event.id).firstOrFail() | ||
| const response = await client.post(`/tasks/${task.slug}/registrations`).json({ | ||
| teamId: team.id, | ||
| }).loginAs(member.user) | ||
|
|
||
| response.assertBadRequest() | ||
| }) | ||
|
|
||
| test('Fails when task has autoregister enabled', async ({ client }) => { | ||
| const user = await User.findByOrFail('nickname', 'user') | ||
| const team = await Team.findByOrFail('name', 'User\'s team') | ||
|
|
||
| const task = await Task.findByOrFail('slug', 'autoregister-task') | ||
| const response = await client.post(`/tasks/${task.slug}/registrations`).json({ | ||
| teamId: team.id, | ||
| }).loginAs(user) | ||
|
|
||
| response.assertBadRequest() | ||
| }) | ||
|
|
||
| test('Fails when team is already registered', async ({ client }) => { | ||
| const user = await User.findByOrFail('nickname', 'user') | ||
| const team = await Team.findByOrFail('name', 'User\'s team') | ||
|
|
||
| const task = await Task.findByUuidOrSlug('visible-task') | ||
| const response = await client.post(`/tasks/${task.slug}/registrations`).json({ | ||
| teamId: team.id, | ||
| }).loginAs(user) | ||
|
|
||
| response.assertConflict() | ||
| }) | ||
|
|
||
| test('Fails when is not authenticated', async ({ client }) => { | ||
| const team = await Team.findByOrFail('name', 'User\'s team') | ||
| const task = await Task.query().where('event_id', team.eventId).firstOrFail() | ||
|
|
||
| const response = await client.post(`/tasks/${task.slug}/registrations`).json({ | ||
| teamId: team.id, | ||
| }) | ||
|
|
||
| response.assertUnauthorized() | ||
| }) | ||
|
|
||
| test('Fails to unregister when does not have permission', async ({ client }) => { | ||
| const normalUser = await User.findByOrFail('nickname', 'normaluser') | ||
| const team = await Team.findByOrFail('name', 'User\'s team') | ||
| const registration = await TaskRegistration.query().where('team_id', team.id).firstOrFail() | ||
|
|
||
| const response = await client.delete(`/registrations/${registration.id}`).loginAs(normalUser) | ||
|
|
||
| response.assertForbidden() | ||
| }) | ||
|
|
||
| test('Fails to unregister when is not authenticated', async ({ client }) => { | ||
| const team = await Team.findByOrFail('name', 'User\'s team') | ||
| const registration = await TaskRegistration.query().where('team_id', team.id).firstOrFail() | ||
|
|
||
| const response = await client.delete(`/registrations/${registration.id}`) | ||
|
|
||
| response.assertUnauthorized() | ||
| }) | ||
| }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.