|
13 | 13 | */ |
14 | 14 |
|
15 | 15 | const { rctData: { detectors } } = require('../../../app/lib/config/configProvider.js'); |
16 | | -const { syncManager } = require('../../../app/lib/alimonitor-services/SyncManager.js'); |
17 | | -const { databaseManager: { repositories: { |
18 | | - RunRepository, |
19 | | - RunDetectorsRepository, |
20 | | - DetectorSubsystemRepository, |
21 | | -}, |
| 16 | +const { syncManager: { |
| 17 | + services: { |
| 18 | + bookkeepingService, |
| 19 | + monalisaService, |
| 20 | + }, |
| 21 | +} } = require('../../../app/lib/alimonitor-services/SyncManager.js'); |
| 22 | +const { databaseManager: { |
| 23 | + repositories: { |
| 24 | + RunRepository, |
| 25 | + RunDetectorsRepository, |
| 26 | + DetectorSubsystemRepository, |
| 27 | + DataPassRepository, |
| 28 | + }, |
| 29 | + models: { |
| 30 | + Run, |
| 31 | + Period, |
| 32 | + }, |
22 | 33 | } } = require('../../../app/lib/database/DatabaseManager.js'); |
23 | | -const { generateRandomBookkeepingCachedRawJsons, cleanCachedBkpData } = require('./testutil/cache-for-test.js'); |
| 34 | +const { generateRandomBookkeepingCachedRawJsons, cleanCachedBkpData } = require('./testutil/bookkeeping-cache-test-data.js'); |
| 35 | +const { generateRandomMonalisaCachedRawJsons, cleanCachedMonalisaData } = require('./testutil/monalisa-cache-test-data.js'); |
24 | 36 | const assert = require('assert'); |
| 37 | +const { expect } = require('chai'); |
| 38 | + |
| 39 | +const artficialDataSizes = { |
| 40 | + bookkeepingService: { |
| 41 | + runsInOneFile: Number(process.env.BKP_RUNS_FETCH_LIMIT || 100), |
| 42 | + filesNo: 2, |
| 43 | + }, |
| 44 | + monalisaService: { |
| 45 | + dataPassesNo: 10, |
| 46 | + minDetailsPerOneDataPass: 1, |
| 47 | + maxDetailsPerOneDataPass: 10, |
| 48 | + }, |
| 49 | +}; |
25 | 50 |
|
26 | 51 | module.exports = () => describe('SyncManager suite', () => { |
27 | | - before('should fetch detectors data from DB the same as in config', async () => await DetectorSubsystemRepository |
| 52 | + before(() => { |
| 53 | + generateRandomBookkeepingCachedRawJsons( |
| 54 | + artficialDataSizes.bookkeepingService.runsInOneFile, |
| 55 | + artficialDataSizes.bookkeepingService.filesNo, |
| 56 | + ); |
| 57 | + generateRandomMonalisaCachedRawJsons( |
| 58 | + artficialDataSizes.monalisaService.dataPassesNo, |
| 59 | + artficialDataSizes.monalisaService.minDetailsPerOneDataPass, |
| 60 | + artficialDataSizes.monalisaService.maxDetailsPerOneDataPass, |
| 61 | + ); |
| 62 | + }); |
| 63 | + |
| 64 | + after(() => { |
| 65 | + cleanCachedBkpData(); |
| 66 | + cleanCachedMonalisaData(); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should fetch detectors data from DB the same as in config', async () => await DetectorSubsystemRepository |
28 | 70 | .findAll({ raw: true }) |
29 | | - .then((detectoSubsystemData) => detectoSubsystemData.map(({ name }) => name)) |
30 | | - .then((detectoSubsystemNames) => assert.deepStrictEqual(detectoSubsystemNames.sort(), detectors.sort()))); |
| 71 | + .then((detectorSubsystemData) => detectorSubsystemData.map(({ name }) => name)) |
| 72 | + .then((detectorSubsystemNames) => expect(detectorSubsystemNames).to.have.same.members(detectors))); |
31 | 73 |
|
32 | 74 | describe('BookkeepingService suite', () => { |
33 | 75 | describe('with artificial cache data', () => { |
34 | | - before(() => { |
35 | | - generateRandomBookkeepingCachedRawJsons(); |
36 | | - }); |
37 | | - |
38 | | - after(() => { |
39 | | - cleanCachedBkpData(); |
40 | | - }); |
41 | | - |
42 | 76 | it('should performe sync with random data withour major errors', async () => { |
43 | | - assert.strictEqual(await syncManager.services.bookkeepingService.setSyncTask(), true); |
| 77 | + bookkeepingService.useCacheJsonInsteadIfPresent = true; |
| 78 | + expect(await bookkeepingService.setSyncTask()).to.be.equal(true); |
44 | 79 | }); |
45 | 80 |
|
46 | 81 | it('should fetch some run data directly from DB', async () => |
47 | 82 | await RunRepository |
48 | 83 | .findAll({ raw: true }) |
49 | | - .then((data) => assert(data.length > 0))); |
| 84 | + .then((data) => expect(data).to.length.greaterThan(0))); //TODO |
50 | 85 |
|
51 | 86 | it('should fetch some run_detector data directly from DB', async () => |
52 | 87 | await RunDetectorsRepository |
53 | 88 | .findAll({ raw: true }) |
54 | | - .then((data) => assert(data.length > 0))); |
| 89 | + .then((data) => expect(data).to.length.greaterThan(0))); //TODO |
55 | 90 | }); |
| 91 | + }); |
56 | 92 |
|
57 | | - describe('without artificial cache data', () => { |
58 | | - before(() => { |
59 | | - syncManager.services.bookkeepingService.forceToUseOnlyCache = true; |
| 93 | + describe('MonalisaService suite', () => { |
| 94 | + describe('with artificial cache data', () => { |
| 95 | + it('should performe sync with random data without major errors', async () => { |
| 96 | + monalisaService.useCacheJsonInsteadIfPresent = true; |
| 97 | + assert.strictEqual(await monalisaService.setSyncTask(), true); |
60 | 98 | }); |
61 | 99 |
|
62 | | - after(() => { |
63 | | - syncManager.services.bookkeepingService.forceToUseOnlyCache = false; |
64 | | - }); |
| 100 | + it('should fetch some data passes with associated Period and Runs directly from DB', async () => { |
| 101 | + const data = await DataPassRepository |
| 102 | + .findAll({ include: [Run, Period] }); |
65 | 103 |
|
66 | | - it('should performe sync with major error', async () => { |
67 | | - assert.strictEqual(await syncManager.services.bookkeepingService.setSyncTask(), false); |
| 104 | + expect(data).to.length.greaterThan(0); //TODO |
| 105 | + expect(data.map(({ Period }) => Period).filter((_) => _)).to.be.lengthOf(data.length); |
68 | 106 | }); |
69 | 107 | }); |
70 | 108 | }); |
|
0 commit comments