-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1604 from notaphplover/feat/add-public-games-page
Add public games page
- Loading branch information
Showing
16 changed files
with
531 additions
and
82 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
140 changes: 140 additions & 0 deletions
140
packages/frontend/web-ui/src/game/helpers/userCanJoinGame.spec.ts
This file contains 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,140 @@ | ||
import { beforeAll, describe, expect, it } from '@jest/globals'; | ||
|
||
import { models as apiModels } from '@cornie-js/api-models'; | ||
|
||
import { userCanJoinGame } from './userCanJoinGame'; | ||
|
||
describe(userCanJoinGame.name, () => { | ||
describe('having an undefined user', () => { | ||
let gameV1Fixture: apiModels.GameV1; | ||
|
||
beforeAll(() => { | ||
gameV1Fixture = { | ||
id: 'game-id', | ||
isPublic: false, | ||
state: { | ||
slots: [], | ||
status: 'nonStarted', | ||
}, | ||
}; | ||
}); | ||
|
||
describe('when called', () => { | ||
let result: unknown; | ||
|
||
beforeAll(() => { | ||
result = userCanJoinGame(gameV1Fixture, undefined); | ||
}); | ||
|
||
it('should return false', () => { | ||
expect(result).toBe(false); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('having an user and a finished game', () => { | ||
let gameV1Fixture: apiModels.FinishedGameV1; | ||
let userV1Fixture: apiModels.UserV1; | ||
|
||
beforeAll(() => { | ||
gameV1Fixture = { | ||
id: 'game-id', | ||
isPublic: false, | ||
state: { | ||
slots: [], | ||
status: 'finished', | ||
}, | ||
}; | ||
|
||
userV1Fixture = { | ||
active: true, | ||
id: 'id', | ||
name: 'name', | ||
}; | ||
}); | ||
|
||
describe('when called', () => { | ||
let result: unknown; | ||
|
||
beforeAll(() => { | ||
result = userCanJoinGame(gameV1Fixture, userV1Fixture); | ||
}); | ||
|
||
it('should return false', () => { | ||
expect(result).toBe(false); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('having an user and a non started game with slot with user id', () => { | ||
let gameV1Fixture: apiModels.NonStartedGameV1; | ||
let userV1Fixture: apiModels.UserV1; | ||
|
||
beforeAll(() => { | ||
userV1Fixture = { | ||
active: true, | ||
id: 'id', | ||
name: 'name', | ||
}; | ||
|
||
gameV1Fixture = { | ||
id: 'game-id', | ||
isPublic: false, | ||
state: { | ||
slots: [ | ||
{ | ||
userId: userV1Fixture.id, | ||
}, | ||
], | ||
status: 'nonStarted', | ||
}, | ||
}; | ||
}); | ||
|
||
describe('when called', () => { | ||
let result: unknown; | ||
|
||
beforeAll(() => { | ||
result = userCanJoinGame(gameV1Fixture, userV1Fixture); | ||
}); | ||
|
||
it('should return false', () => { | ||
expect(result).toBe(false); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('having an user and a non started game without slot with user id', () => { | ||
let gameV1Fixture: apiModels.NonStartedGameV1; | ||
let userV1Fixture: apiModels.UserV1; | ||
|
||
beforeAll(() => { | ||
userV1Fixture = { | ||
active: true, | ||
id: 'id', | ||
name: 'name', | ||
}; | ||
|
||
gameV1Fixture = { | ||
id: 'game-id', | ||
isPublic: false, | ||
state: { | ||
slots: [], | ||
status: 'nonStarted', | ||
}, | ||
}; | ||
}); | ||
|
||
describe('when called', () => { | ||
let result: unknown; | ||
|
||
beforeAll(() => { | ||
result = userCanJoinGame(gameV1Fixture, userV1Fixture); | ||
}); | ||
|
||
it('should return true', () => { | ||
expect(result).toBe(true); | ||
}); | ||
}); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
packages/frontend/web-ui/src/game/helpers/userCanJoinGame.ts
This file contains 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,15 @@ | ||
import { models as apiModels } from '@cornie-js/api-models'; | ||
|
||
export function userCanJoinGame( | ||
game: apiModels.GameV1, | ||
user: apiModels.UserV1 | undefined, | ||
): boolean { | ||
return ( | ||
user !== undefined && | ||
game.state.status === 'nonStarted' && | ||
!game.state.slots.some( | ||
(slot: apiModels.NonStartedGameSlotV1): boolean => | ||
slot.userId === user.id, | ||
) | ||
); | ||
} |
Oops, something went wrong.