File size: 887 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// This script gets run once before all tests
// It's responsible for setting up the test db with the test data
const path = require('path');
const debug = require('debug')('testing:setup');
const { migrate } = require('rethinkdb-migrate/lib');

const mockDb = require('./db');
const data = require('./data');

const tables = Object.keys(data);

module.exports = async () => {
  debug(`run all migrations over database "testing"`);
  await migrate({
    driver: 'rethinkdbdash',
    host: 'localhost',
    port: 28015,
    migrationsDirectory: path.resolve(__dirname, '../../api/migrations'),
    db: 'testing',
    op: 'up',
  });

  debug(`migrations complete, inserting data into "testing"`);
  await Promise.all(
    tables.map(table =>
      mockDb
        .table(table)
        .insert(data[table], { conflict: 'replace' })
        .run()
    )
  );

  debug(`setup complete`);
};