3 const env = require('gitter-web-env');
4 const logger = env.logger;
5 const express = require('express');
6 const asyncHandler = require('express-async-handler');
7 const identifyRoute = require('gitter-web-env').middlewares.identifyRoute;
9 const fixtureLoader = require('gitter-web-test-utils/lib/test-fixtures');
11 const router = express.Router({ caseSensitive: true, mergeParams: true });
15 identifyRoute('fixtures'),
16 asyncHandler(async (req, res) => {
17 const fixtures = await fixtureLoader.createExpectedFixtures(req.body);
19 const fixtureResponse = Object.keys(req.body).reduce((partialResponse, fixtureKey) => {
20 partialResponse[fixtureKey] = fixtures[fixtureKey].toJSON();
22 // A hack around the serialization and our fixtures adding extra properties onto the Mongoose object
23 // See `modules/test-utils/lib/create-users.js`
24 if (fixtureKey.match(/^user/)) {
25 partialResponse[fixtureKey].accessToken = fixtures[fixtureKey].accessToken;
28 return partialResponse;
31 logger.info('Fixture endpoint generated some new fixtures', fixtureResponse);
33 res.send(fixtureResponse);
37 module.exports = router;