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

init tests #466

Merged
merged 1 commit into from
Nov 18, 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
1 change: 1 addition & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ jobs:
- run: yarn install
# --force should be removed if all the issues are fixed
- run: ./node_modules/.bin/grunt jshint --force
- run: yarn run test
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@
"grunt-nodemon": "^0.4.2",
"grunt-postcss": "0.9.0",
"grunt-sass": "3.1.0",
"jest": "^29.7.0",
"jshint-stylish": "2.2.1",
"load-grunt-config": "4.0.1",
"load-grunt-tasks": "5.1.0"
"load-grunt-tasks": "5.1.0",
"supertest": "^6.3.3"
},
"engines": {
"node": ">=20.9.0",
"yarn": ">=1.22.0"
},
"scripts": {
"start": "node express.js"
"start": "node express.js",
"test": "jest"
},
"main": "express.js"
}
48 changes: 48 additions & 0 deletions tests/integration/NewsRouter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const request = require('supertest')
const express = require('express')
const newsRouter = require( "../../routes/views/news")
const fs = require('fs')

const app = new express();
app.set('views', 'templates/views');
app.set('view engine', 'pug');
app.use("/news", newsRouter)

describe('News Routes', function () {
const testFile = fs.readFileSync('tests/integration/testData/news.json',{encoding:'utf8', flag:'r'})

test('responds to /', async () => {
jest.mock('fs')
jest.spyOn(fs, 'readFileSync').mockReturnValueOnce(testFile)


const res = await request(app).get('/news');
expect(res.header['content-type']).toBe('text/html; charset=utf-8');
expect(res.statusCode).toBe(200);
expect(res.text).toContain('Welcome to the patchnotes for the 3750 patch.');
expect(res.text).toContain('New FAF Website');
expect(res.text).toContain('Game version 3738');
expect(res.text).toContain('Weapon Target Checking Intervals');
});

test('responds to /:slug', async () => {
jest.mock('fs')
jest.spyOn(fs, 'readFileSync').mockReturnValueOnce(testFile)


const res = await request(app).get('/news/balance-patch-3750-is-live');
expect(res.header['content-type']).toBe('text/html; charset=utf-8');
expect(res.statusCode).toBe(200);
expect(res.text).toContain('Welcome to the patchnotes for the 3750 patch.');
});

test('responds to /:slug with redirect if called with old slug', async () => {
jest.mock('fs')
jest.spyOn(fs, 'readFileSync').mockReturnValueOnce(testFile)


const res = await request(app).get('/news/Balance-Patch-3750-Is-Live');
expect(res.statusCode).toBe(301);
expect(res.header['location']).toBe('balance-patch-3750-is-live');
});
});