Skip to content

Commit

Permalink
organize setup a bit - fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
beckpaul committed Dec 5, 2023
1 parent 2514fa6 commit fc0e862
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
23 changes: 7 additions & 16 deletions tests/integration/accountRouter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,18 @@ describe('Account Routes', function () {
expect(response.statusCode).toBe(200)
})

test('redirect to reset request page if missing username parameter with flash parameter', async () => {
test('render request content if missing username parameter with flash', async () => {
const response = await testSession.get('/account/password/confirmReset?token=XXXXX')

expect(response.statusCode).toBe(302)
expect(response.headers.location).toContain('/account/requestPasswordReset?flash=')

const redirectResponse = await testSession.get(response.headers.location)

expect(redirectResponse.text).toContain('Missing username')
expect(response.statusCode).toBe(200)
expect(response.text).toContain('Missing username')
})

test('redirect to reset request page if missing token parameter with flash parameter', async () => {
const response = await testSession.get('/account/password/confirmReset?username=turbo2')

const flashValue = response.headers.location.match(/flash=([^&]+)/)[1]
const buff = Buffer.from(flashValue, 'base64')
const text = JSON.parse(buff.toString('ascii')).messages[0].msg
test('render request content if missing token parameter with flash', async () => {
const response = await testSession.get('/account/password/confirmReset?token=XXXXX')

expect(response.statusCode).toBe(302)
expect(response.headers.location).toContain('/account/requestPasswordReset?flash=')
expect(text).toBe('Missing token')
expect(response.statusCode).toBe(200)
expect(response.text).toContain('Missing username')
})

test('redirect old pw-reset routes', async () => {
Expand Down
12 changes: 5 additions & 7 deletions tests/setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs')
const { WordpressService } = require('../src/backend/services/WordpressService')
const { LeaderboardService } = require('../src/backend/services/LeaderboardService')
const { JavaApiM2MClient } = require('../src/backend/services/JavaApiM2MClient')
const appConfig = require('../src/backend/config/app')
const nock = require('nock')
nock.disableNetConnect()
Expand Down Expand Up @@ -36,27 +37,24 @@ beforeEach(() => {
throw new Error('do we need to change the mock?')
})

nock(appConfig.apiUrl)
.post('/users/buildSteamPasswordResetUrl')
.reply(200, { steamUrl: 'http://localhost/test-steam-reset' })

jest.spyOn(JavaApiM2MClient, 'getToken').mockResolvedValue({
token: {
refresh: () => {},
access_token: 'test'
}
})

nock(appConfig.apiUrl)
.post('/users/buildSteamPasswordResetUrl')
.reply(200, { steamUrl: 'http://localhost/test-steam-reset' })

nock(appConfig.apiUrl)
.get('/data/clan?include=leader&fields[clan]=name,tag,description,leader,memberships,createTime&fields[player]=login&page[number]=1&page[size]=3000')
.reply(200, fs.readFileSync('tests/integration/testData/clan/clans.json', { encoding: 'utf8', flag: 'r' }))

nock(appConfig.apiUrl)
.get('/data/clan/2741?include=memberships.player')
.reply(200, fs.readFileSync('tests/integration/testData/clan/clan.json', { encoding: 'utf8', flag: 'r' }))
nock(appConfig.apiUrl)
.post('/users/buildSteamPasswordResetUrl')
.reply(200, { steamUrl: 'http://localhost/test-steam-reset' })
})

afterEach(() => {
Expand Down

0 comments on commit fc0e862

Please sign in to comment.