Skip to content
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

fix test coverage, mocks and flash #1

Merged
merged 1 commit into from
Dec 4, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ exports = module.exports = async function (req, res) {
section: 'account',
flash: {
class: 'alert-danger',
messages: 'issue resetting',
messages: [{ msg: 'issue resetting' }],
type: 'Error!'
},
formData,
Expand Down
9 changes: 4 additions & 5 deletions tests/integration/accountRouter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ describe('Account Routes', function () {
test('redirect to reset request page if missing username parameter with flash parameter', async () => {
const response = await testSession.get('/account/password/confirmReset?token=XXXXX')

const flashValue = response.headers.location.match(/flash=([^&]+)/)[1]
const buff = Buffer.from(flashValue, 'base64')
const text = JSON.parse(buff.toString('ascii')).messages[0].msg

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

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

expect(redirectResponse.text).toContain('Missing username')
})

test('redirect to reset request page if missing token parameter with flash parameter', async () => {
Expand Down
5 changes: 5 additions & 0 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 appConfig = require('../src/backend/config/app')
const nock = require('nock')
nock.disableNetConnect()
nock.enableNetConnect('127.0.0.1')
Expand Down Expand Up @@ -34,6 +35,10 @@ 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' })
})

afterEach(() => {
Expand Down