/**
* This file is a mock file to pre-generate some data in to the application
*/
/**
* Import Relationship Model
*/
const Relationship = require('./models/relationship');
const UserService = require('./services/user.service');
const CardController = require('./controllers/card');
const User = require('./models/user');
const CardMock = require('./test/mockData/card.mock');
const UserMock = require('./test/mockData/user.mock');
/**
* Dependencies and config
*/
const path = require('path');
const mongoose = require('mongoose');
const config = require('./config');
const runIOSMock = async () => {
try {
mongoose.connect(`${config.db.uri}`, { useMongoClient: true });
await User.remove({});
await Relationship.remove({});
const { reqs } = CardMock;
const authenticatedUser1 = await User.create(UserMock.user1);
const authenticatedUser2 = await User.create(UserMock.user2);
const authenticatedUser3 = await User.create(UserMock.user3);
const filePath1 = { path: path.resolve('./test/mockData/img/Ralfs_Lagzda.png') };
const filePath2 = { path: path.resolve('./test/mockData/img/Karlis_Filipsons.png') };
const filePath3 = { path: path.resolve('./test/mockData/img/Elina_Baumane.png') };
await UserService.modifyProfilePicture(authenticatedUser1, filePath1);
await UserService.modifyProfilePicture(authenticatedUser2, filePath2);
await UserService.modifyProfilePicture(authenticatedUser3, filePath3);
const relationship1 = {
sharingUser: authenticatedUser1.id,
receivingUser: authenticatedUser2.id,
sharedCards: [],
createdBy: authenticatedUser1.id,
};
const relationship2 = {
sharingUser: authenticatedUser2.id,
receivingUser: authenticatedUser1.id,
sharedCards: [],
createdBy: authenticatedUser1.id,
};
const relationship3 = {
sharingUser: authenticatedUser3.id,
receivingUser: authenticatedUser1.id,
sharedCards: [],
createdBy: authenticatedUser1.id,
};
await Promise.all(reqs.map(async (req, index) => {
if (index > 7) {
req.params.userId = authenticatedUser3.id;
const card = await CardController.create(req);
relationship3.sharedCards.push(card);
} else if (index > 5) {
req.params.userId = authenticatedUser2.id;
const card = await CardController.create(req);
relationship2.sharedCards.push(card);
} else {
req.params.userId = authenticatedUser1.id;
const card = await CardController.create(req);
relationship1.sharedCards.push(card);
}
}));
await Relationship.create(relationship1);
await Relationship.create(relationship2);
await Relationship.create(relationship3);
mongoose.connection.close();
} catch (err) {
throw err;
}
};
runIOSMock();
|