-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlobalObjects.js
76 lines (63 loc) · 2.99 KB
/
GlobalObjects.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const Controller = require('./src/Controller');
const Mediator = require('./src/Mediator');
const BoxerRepository = require('./src/Repository/BoxerRepository');
const MockBoxerRepository = require('./src/Repository/Mock/MockBoxerRepository');
const StandingsServiceGateway = require('./src/Gateway/StandingsServiceGateway');
const MockStandingsServiceGateway = require('./src/Gateway/Mock/MockStandingsServiceGateway');
const AuthServiceGateway = require('./src/Gateway/AuthServiceGateway');
const MockAuthServiceGateway = require('./src/Gateway/Mock/MockAuthServiceGateway');
const MatchServiceGateway = require('./src/Gateway/MatchServiceGateway');
const MockMatchServiceGateway = require('./src/Gateway/Mock/MockMatchServiceGateway');
// GRPC SETUP
const grpc = require('grpc');
const protoLoader = require('@grpc/proto-loader');
const PROTO_PATH = __dirname + '/proto/ubc.proto';
const packageDefinition = protoLoader.loadSync(PROTO_PATH, { keepCase: true, longs: String, enums: String, defaults: true, oneofs: true });
const ubc_package = grpc.loadPackageDefinition(packageDefinition).ubc_package;
class GlobalObjects {
constructor() {
this.unreturnableContentForResult = "globalObjectsUnreturnableContent";
this.done = false;
this.result = this.unreturnableContentForResult; // Result object that will be filled during tests.
this.controller = new Controller();
this.mediator = new Mediator();
this.boxerRepository = new BoxerRepository();
this.standingsServiceGateway = new StandingsServiceGateway();
this.authServiceGateway = new AuthServiceGateway();
this.matchServiceGateway = new MatchServiceGateway();
this.client = new ubc_package.BoxerService(process.env.BOXER_SERVICE_ADDR || "0.0.0.0:50052", grpc.credentials.createInsecure());
}
// Mock everything...
mock() {
this.mediator.mock();
this.boxerRepository = new MockBoxerRepository();
this.standingsServiceGateway = new MockStandingsServiceGateway();
this.authServiceGateway = new MockAuthServiceGateway();
this.matchServiceGateway = new MockMatchServiceGateway();
}
resetResult() {
this.result = null;
}
setScenario(scenario) {
this.scenario = scenario;
}
setScenarioTester(scenarioTester) {
this.scenarioTester = scenarioTester;
}
reset() {
this.result = this.unreturnableContentForResult; // Result object that will be filled during tests.
this.controller = new Controller();
this.mediator = new Mediator();
this.boxerRepository = new BoxerRepository();
this.standingsServiceGateway = new StandingsServiceGateway();
this.authServiceGateway = new AuthServiceGateway();
this.matchServiceGateway = new MatchServiceGateway();
this.client = new ubc_package.BoxerService(process.env.BOXER_SERVICE_ADDR || "0.0.0.0:50052", grpc.credentials.createInsecure());
}
async cleanUp() {
await this.boxerRepository.cleanUp();
await this.standingsServiceGateway.cleanUp();
await this.matchServiceGateway.cleanUp();
}
}
module.exports = GlobalObjects;