mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
test: add cypress foundation (#2903) [skip ci]
This commit is contained in:
53
server/scripts/prepareTestDb.ts
Normal file
53
server/scripts/prepareTestDb.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { createConnection, getRepository } from 'typeorm';
|
||||
import { copyFileSync } from 'fs';
|
||||
import { UserType } from '../constants/user';
|
||||
import { User } from '../entity/User';
|
||||
import path from 'path';
|
||||
|
||||
const prepareDb = async () => {
|
||||
// Copy over test settings.json
|
||||
copyFileSync(
|
||||
path.join(__dirname, '../../cypress/config/settings.cypress.json'),
|
||||
path.join(__dirname, '../../config/settings.json')
|
||||
);
|
||||
|
||||
// Connect to DB and seed test data
|
||||
const dbConnection = await createConnection();
|
||||
|
||||
await dbConnection.dropDatabase();
|
||||
|
||||
// Run migrations in production
|
||||
if (process.env.WITH_MIGRATIONS === 'true') {
|
||||
await dbConnection.runMigrations();
|
||||
} else {
|
||||
await dbConnection.synchronize();
|
||||
}
|
||||
|
||||
const userRepository = getRepository(User);
|
||||
|
||||
// Create the admin user
|
||||
const user = new User();
|
||||
user.plexId = 1;
|
||||
user.plexToken = '1234';
|
||||
user.plexUsername = 'admin';
|
||||
user.username = 'admin';
|
||||
user.email = 'admin@seerr.dev';
|
||||
user.userType = UserType.PLEX;
|
||||
await user.setPassword('test1234');
|
||||
user.permissions = 2;
|
||||
user.avatar = 'https://plex.tv/assets/images/avatar/default.png';
|
||||
await userRepository.save(user);
|
||||
|
||||
// Create the other user
|
||||
const otherUser = new User();
|
||||
otherUser.plexId = 1;
|
||||
otherUser.username = 'friend';
|
||||
otherUser.email = 'friend@seerr.dev';
|
||||
otherUser.userType = UserType.LOCAL;
|
||||
await otherUser.setPassword('test1234');
|
||||
otherUser.permissions = 32;
|
||||
otherUser.avatar = 'https://plex.tv/assets/images/avatar/default.png';
|
||||
await userRepository.save(otherUser);
|
||||
};
|
||||
|
||||
prepareDb();
|
Reference in New Issue
Block a user