Skip to content

Commit

Permalink
init tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fcaps committed Nov 17, 2023
1 parent 2288b1f commit 07156f4
Show file tree
Hide file tree
Showing 5 changed files with 1,530 additions and 31 deletions.
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');
});
});
Loading

0 comments on commit 07156f4

Please sign in to comment.