This repository has been archived by the owner on Jan 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mock CompetitionInfo and create more Test Competitions (#300)
* Add more Test Competitions * Fix bug where Favourites competition throws an error * Added actual type for teams * fix eslint * Make sure test competitions don't get out of date * add cypress to test file * Add tests and fix issues arisen by tests * Add more tests and fix issues arisen by tests * renamed mock function * add mock function to backend * fix rubocop issues * added base_url * move jwt mock to backend * run rubocop * disable automatic running of frontend tests * remove whitespace
- Loading branch information
1 parent
74377e9
commit 8fed738
Showing
24 changed files
with
3,224 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
import externalServiceFetch from '../../helper/external_service_fetch' | ||
import { competitionInfoRoute } from '../../helper/routes' | ||
import getCompetitionInfoMockWithRealFallback from '../../mocks/get_competition_info' | ||
import { CompetitionInfo } from '../../types' | ||
|
||
export default async function getCompetitionInfo( | ||
competitionId: string | ||
): Promise<CompetitionInfo> { | ||
if (process.env.NODE_ENV !== 'production') { | ||
return getCompetitionInfoMockWithRealFallback(competitionId) | ||
} | ||
return externalServiceFetch(competitionInfoRoute(competitionId)) | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,39 @@ | ||
import getCompetitionInfo from '../competition/get/get_competition_info' | ||
import { CompetitionInfo } from '../types' | ||
import { | ||
CLOSED_COMPETITION, | ||
COMMENT_REQUIRED, | ||
FAVOURITES_COMPETITION, | ||
NOT_YET_OPEN, | ||
OPEN_COMPETITION, | ||
OPEN_WITH_PAYMENTS, | ||
} from './fixtures' | ||
|
||
export default async function getCompetitionInfoMockWithRealFallback( | ||
competitionId: string | ||
): Promise<CompetitionInfo> { | ||
switch (competitionId) { | ||
case 'KoelnerKubing2023': { | ||
return OPEN_COMPETITION | ||
} | ||
case 'RheinNeckarAutumn2023': { | ||
return OPEN_WITH_PAYMENTS | ||
} | ||
case 'HessenOpen2023': { | ||
return CLOSED_COMPETITION | ||
} | ||
case 'ManchesterSpring2024': { | ||
return NOT_YET_OPEN | ||
} | ||
case 'FMCFrance2023': { | ||
return COMMENT_REQUIRED | ||
} | ||
case 'PickeringFavouritesAutumn2023': { | ||
return FAVOURITES_COMPETITION | ||
} | ||
default: { | ||
// This allows non mocked response when debugging a certain competition | ||
return getCompetitionInfo(competitionId) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,20 +1,8 @@ | ||
import Base64 from 'crypto-js/enc-base64' | ||
import md5 from 'crypto-js/md5' | ||
import * as jose from 'jose' | ||
import { USER_KEY } from '../../ui/providers/UserProvider' | ||
|
||
export default async function getJWTMock(): Promise<string> { | ||
const user = localStorage.getItem(USER_KEY) | ||
const secret = new TextEncoder().encode('jwt-test-secret') | ||
const alg = 'HS256' | ||
const issuedAt = Date.now() | ||
const jwt = await new jose.SignJWT({ user_id: user }) | ||
.setProtectedHeader({ alg }) | ||
.setIssuedAt(issuedAt) | ||
.setJti(Base64.stringify(md5(`${secret}:${issuedAt}`))) | ||
.setIssuer('wca-registration-test-frontend') | ||
.setAudience('wca-registration-test-backend') | ||
.setExpirationTime('30m') | ||
.sign(secret) | ||
return `Bearer: ${jwt}` | ||
const response = await fetch(`http://localhost:3001/test/jwt/${user}`) | ||
const data = await response.json() | ||
return `Bearer: ${data.token}` | ||
} |
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
Oops, something went wrong.