3 const env = require('gitter-web-env');
4 const config = env.config;
5 const logger = env.logger.get('matrix-bridge/test/util/ensure-matrix-fixtures');
7 const createUsers = require('gitter-web-test-utils/lib/create-users');
8 const createGroups = require('gitter-web-test-utils/lib/create-groups');
9 const groupService = require('gitter-web-groups');
10 const userService = require('gitter-web-users');
12 const gitterBridgeBackingUsername = config.get('matrix:bridge:gitterBridgeBackingUsername');
13 const gitterBridgeProfileUsername = config.get('matrix:bridge:gitterBridgeProfileUsername');
15 async function ensureMatrixFixtures() {
16 const userFixtures = {};
18 // Create the backing bridge user on the Gitter side if it doesn't already exist.
19 // We don't have access to dependency inject this like we do in the smaller unit tests
20 // so let's just create the user like it exists for real.
21 const gitterBridgeBackingUser = await userService.findByUsername(gitterBridgeBackingUsername);
22 if (!gitterBridgeBackingUser) {
24 `Matrix gitterBridgeBackingUser not found, creating test fixture user (${gitterBridgeBackingUsername}) to smooth it over.`
26 userFixtures.userBridge1 = {
27 username: gitterBridgeBackingUsername
31 // Create the profile bridge user on the Gitter side if it doesn't already exist.
32 // We don't have access to dependency inject this like we do in the smaller unit tests
33 // so let's just create the user like it exists for real.
34 const gitterBridgeProfileUser = await userService.findByUsername(gitterBridgeProfileUsername);
36 !gitterBridgeProfileUser &&
37 // Also make sure we're not trying to create the same user if they are configured to be the same
38 gitterBridgeProfileUsername !== gitterBridgeBackingUsername
41 `Matrix gitterBridgeProfileUser not found, creating test fixture user (${gitterBridgeProfileUsername}) to smooth it over.`
43 userFixtures.userBridgeProfile1 = {
44 username: gitterBridgeProfileUsername
48 // Re-using the test fixture setup functions
50 await createUsers(userFixtures, f);
52 const matrixDmGroup = await groupService.findByUri('matrix', { lean: true });
54 logger.info('Matrix DM group not found, creating test fixture group to smooth it over.');
56 // Re-using the test fixture setup functions
69 module.exports = ensureMatrixFixtures;