-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #493 from parlemonde/new-e2e-test
New e2e test
- Loading branch information
Showing
27 changed files
with
808 additions
and
32 deletions.
There are no files selected for viewing
Binary file added
BIN
+52.7 KB
.yarn/cache/@mapbox-node-pre-gyp-npm-1.0.10-1811160047-1a98db05d9.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import type { Request as ExpressRequest, Response as ExpressResponse } from 'express'; | ||
import supertest from 'supertest'; | ||
|
||
import { getApp } from '../app'; | ||
import { Activity } from '../entities/activity'; | ||
import { User } from '../entities/user'; | ||
import { Village } from '../entities/village'; | ||
import { appDataSource, fakeUser, loginUser } from './mock'; | ||
|
||
// Mock connection to database to avoid error message in console. | ||
jest.mock('../utils/database', () => ({ | ||
connection: Promise.resolve(), | ||
})); | ||
// Mock nodemailer to avoid message in console. | ||
jest.mock('../emails/nodemailer', () => ({ | ||
__esModule: true, | ||
getNodeMailer: async () => ({ | ||
t: null, | ||
}), | ||
})); | ||
|
||
// Mock frontend NextJS library. We don't need it for testing. | ||
jest.mock('next', () => ({ | ||
__esModule: true, | ||
default: () => ({ | ||
getRequestHandler: () => (_req: ExpressRequest, res: ExpressResponse) => { | ||
res.sendJSON({ isFrontend: true }); | ||
}, | ||
prepare: () => Promise.resolve(), | ||
}), | ||
})); | ||
|
||
jest.mock('../authentication/login', () => ({ | ||
__esModule: true, | ||
login: async () => ({ | ||
user: fakeUser, | ||
}), | ||
})); | ||
|
||
export const activity = { | ||
id: 18, | ||
type: 4, | ||
phase: 2, | ||
status: 0, | ||
data: { | ||
game1: { video: 'https://vimeo.com/36273186', gameId: 1, origine: 'b', signification: 'a', fakeSignification1: 'c', fakeSignification2: 'd' }, | ||
game2: { | ||
video: 'https://vimeo.com/134108914', | ||
gameId: 2, | ||
origine: 'origin', | ||
signification: 'bubble', | ||
fakeSignification1: 'test', | ||
fakeSignification2: 'test', | ||
}, | ||
game3: { | ||
video: 'https://vimeo.com/221414987', | ||
gameId: 3, | ||
origine: 'origin', | ||
signification: 'real', | ||
fakeSignification1: 'fake 1', | ||
fakeSignification2: 'fake 2', | ||
}, | ||
draftUrl: '/creer-un-jeu/mimique/3', | ||
presentation: 'La classe de CE 2 à Paris', | ||
}, | ||
content: [{ id: 0, type: 'text', value: '' }], | ||
userId: 6, | ||
villageId: 1, | ||
createDate: Date, | ||
updateDate: Date, | ||
deleteDate: null, | ||
subType: 0, | ||
responseActivityId: null, | ||
responseType: null, | ||
isPinned: 0, | ||
displayUser: 0, | ||
games: [], | ||
images: [], | ||
user: User, | ||
village: Village, | ||
responseActivity: Activity, | ||
}; | ||
|
||
export const mimique = { | ||
id: 1, | ||
type: 0, | ||
content: { fakeSignification1: 'c', fakeSignification2: 'd', origine: 'b', signification: 'a', video: 'https://vimeo.com/36273186' }, | ||
userId: 6, | ||
villageId: 1, | ||
activityId: 18, | ||
value: '', | ||
}; | ||
|
||
describe('game', () => { | ||
beforeAll(() => { | ||
return appDataSource.initialize(); | ||
}); | ||
afterAll(() => { | ||
// return conn.close(); | ||
return appDataSource.destroy(); | ||
}); | ||
|
||
describe('get games', () => { | ||
const auth = { token: '' }; | ||
beforeAll(async () => { | ||
return loginUser(auth); | ||
}); | ||
|
||
describe('given game does not exist', () => { | ||
it('should return 404', async () => { | ||
const gameId = 'game-123'; | ||
try { | ||
const app = await getApp(); | ||
await supertest(app).get(`/api/games/${gameId}`).expect(404); | ||
} catch (e) { | ||
expect(400); | ||
} | ||
}); | ||
}); | ||
|
||
describe('given game does exist', () => { | ||
it('should return 200 status and the game', async () => { | ||
const game = mimique; | ||
try { | ||
const app = await getApp(); | ||
const { body, statusCode } = await supertest(app) | ||
.get(`/api/games/${game.id}`) | ||
.set({ Authorization: 'bearer ' + auth.token, 'Content-Type': 'application/json' }); | ||
expect(statusCode).toBe(200); | ||
expect(body.id).toEqual(game.id); | ||
} catch (e) { | ||
expect(400); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import path from 'path'; | ||
import supertest from 'supertest'; | ||
import { DataSource } from 'typeorm'; | ||
|
||
import { getApp } from '../app'; | ||
|
||
export const appDataSource = new DataSource({ | ||
type: 'sqlite', | ||
database: ':memory:', | ||
dropSchema: true, | ||
entities: [path.join(__dirname, '../entities/*.js')], | ||
synchronize: true, | ||
logging: false, | ||
}); | ||
|
||
/** | ||
* function to create a token for the use of PLM's api | ||
* @param auth empty object with token string property | ||
* @returns auth with token inside | ||
*/ | ||
export function loginUser(auth: { token: string }) { | ||
return async function () { | ||
const app = await getApp(); | ||
supertest(app) | ||
.post('/login') | ||
.send({ | ||
email: '[email protected]', | ||
password: 'helloWorld*', | ||
}) | ||
.expect(200) | ||
.end(function (err, res) { | ||
if (err) throw err; | ||
return (auth.token = res.body.token); | ||
}); | ||
}; | ||
} | ||
/** | ||
* Mock for fake user to the response for login request | ||
*/ | ||
export const fakeUser = { | ||
id: 1, | ||
email: '[email protected]', | ||
pseudo: 'teacher1', | ||
level: 'CM1', | ||
school: 'École polyvalente publique Tandou', | ||
city: 'Paris', | ||
postalCode: '75019', | ||
address: '16 Rue Tandou, 75019 Paris', | ||
avatar: null, | ||
displayName: null, | ||
accountRegistration: 0, | ||
passwordHash: '$argon2i$v=19$m=16,t=2,p=1$cTY0aFpyUmF2ZkhERnRSQQ$j7XF79KQqmGGay1bqtxNuQ', | ||
firstLogin: 3, | ||
type: 0, | ||
villageId: 1, | ||
country: { isoCode: 'FR', name: 'France' }, | ||
position: { lat: 48.8863442, lng: 2.380321 }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import type { Request as ExpressRequest, Response as ExpressResponse } from 'express'; | ||
import supertest from 'supertest'; | ||
|
||
import { getApp } from '../app'; | ||
import { appDataSource, fakeUser } from './mock'; | ||
|
||
// Mock connection to database to avoid error message in console. | ||
jest.mock('../utils/database', () => ({ | ||
connection: Promise.resolve(), | ||
})); | ||
// Mock nodemailer to avoid message in console. | ||
jest.mock('../emails/nodemailer', () => ({ | ||
__esModule: true, | ||
getNodeMailer: async () => ({ | ||
t: null, | ||
}), | ||
})); | ||
|
||
// Mock frontend NextJS library. We don't need it for testing. | ||
jest.mock('next', () => ({ | ||
__esModule: true, | ||
default: () => ({ | ||
getRequestHandler: () => (_req: ExpressRequest, res: ExpressResponse) => { | ||
res.sendJSON({ isFrontend: true }); | ||
}, | ||
prepare: () => Promise.resolve(), | ||
}), | ||
})); | ||
|
||
jest.mock('../authentication/login', () => ({ | ||
__esModule: true, | ||
login: async () => ({ | ||
user: fakeUser, | ||
}), | ||
})); | ||
|
||
describe('test entry point', () => { | ||
beforeAll(() => { | ||
return appDataSource.initialize(); | ||
}); | ||
afterAll(() => { | ||
// return conn.close(); | ||
return appDataSource.destroy(); | ||
}); | ||
describe('server and login', () => { | ||
describe('server is OK', () => { | ||
it('should return 200', async () => { | ||
try { | ||
const app = await getApp(); | ||
|
||
await supertest(app).get('/api').expect(200); | ||
} catch (e) { | ||
expect(400); | ||
} | ||
}); | ||
}); | ||
|
||
describe('Login is', () => { | ||
it('should return 200', async () => { | ||
try { | ||
const app = await getApp(); | ||
const response = await supertest(app).post('/login').set('Accept', 'application/json'); | ||
expect(response.status).toBe(200); | ||
} catch (e) { | ||
expect(400); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import type { Request as ExpressRequest, Response as ExpressResponse } from 'express'; | ||
import supertest from 'supertest'; | ||
|
||
import { getApp } from '../app'; | ||
import { appDataSource, fakeUser, loginUser } from './mock'; | ||
|
||
// Mock connection to database to avoid error message in console. | ||
jest.mock('../utils/database', () => ({ | ||
connection: Promise.resolve(), | ||
})); | ||
// Mock nodemailer to avoid message in console. | ||
jest.mock('../emails/nodemailer', () => ({ | ||
__esModule: true, | ||
getNodeMailer: async () => ({ | ||
t: null, | ||
}), | ||
})); | ||
|
||
// Mock frontend NextJS library. We don't need it for testing. | ||
jest.mock('next', () => ({ | ||
__esModule: true, | ||
default: () => ({ | ||
getRequestHandler: () => (_req: ExpressRequest, res: ExpressResponse) => { | ||
res.sendJSON({ isFrontend: true }); | ||
}, | ||
prepare: () => Promise.resolve(), | ||
}), | ||
})); | ||
|
||
jest.mock('../authentication/login', () => ({ | ||
__esModule: true, | ||
login: async () => ({ | ||
user: fakeUser, | ||
}), | ||
})); | ||
|
||
describe('Story api test', () => { | ||
beforeAll(() => { | ||
return appDataSource.initialize(); | ||
}); | ||
afterAll(() => { | ||
// return conn.close(); | ||
return appDataSource.destroy(); | ||
}); | ||
describe('Images use in original stories', () => { | ||
const auth = { token: '' }; | ||
beforeAll(async () => { | ||
return loginUser(auth); | ||
}); | ||
|
||
describe('api call images/all', () => { | ||
it('should return ALL images', async () => { | ||
try { | ||
const app = await getApp(); | ||
await supertest(app).get(`/api/stories/all`).expect(200); | ||
} catch (e) { | ||
expect(404); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.