Skip to content

Commit

Permalink
#17 setup test DB and JWT mock for API testing
Browse files Browse the repository at this point in the history
  • Loading branch information
blms committed Jul 27, 2020
1 parent 1b4650d commit 4a428f0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
'!**/*.d.ts',
'!**/node_modules/**',
],
setupFiles: ['<rootDir>/src/setupEnv.js'],
setupFilesAfterEnv: ['<rootDir>/src/setupTests.js'],
testPathIgnorePatterns: ['/node_modules/', '/.next/'],
transform: {
Expand Down
17 changes: 17 additions & 0 deletions src/__mocks__/next-auth/jwt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { getObjectId } = require('mongo-seeding');

const jwt = jest.genMockFromModule('next-auth/jwt');

function getJwt() {
return {
exp: 1000,
user: {
id: getObjectId('test-user'),
name: 'Test User',
email: '[email protected]',
},
};
}

jwt.getJwt = getJwt;
module.exports = jwt;
2 changes: 2 additions & 0 deletions src/setupEnv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
process.env.MONGODB_URI = 'mongodb://localhost:27017/as4-test';
process.env.DB_NAME = 'as4-test';

0 comments on commit 4a428f0

Please sign in to comment.