-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
63 lines (49 loc) · 1.78 KB
/
test.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
const fs = require('fs');
const AWS = require('aws-sdk');
const yaml = require('js-yaml');
const moxios = require('moxios');
const accessToken = require('./test/mocks/AccessTokenMock');
const bib_response = fs.readFileSync(require('path').resolve(__dirname, 'test/mocks/bibResponse.xml')).toString();
const error_response_401 = fs.readFileSync(require('path').resolve(__dirname, 'test/mocks/errorResponse.xml')).toString();
const error_response_403 = fs.readFileSync(require('path').resolve(__dirname, 'test/mocks/errorResponse_403.xml')).toString();
const error_response_404 = fs.readFileSync(require('path').resolve(__dirname, 'test/mocks/errorResponse_404.xml')).toString();
moxios.install();
moxios.stubRequest('https://worldcat.org/bib/data/70775700', {
status: 200,
responseText: bib_response
});
moxios.stubRequest('https://worldcat.org/bib/data/401', {
status: 401,
responseText: error_response_401
});
moxios.stubRequest('https://worldcat.org/bib/data/403', {
status: 403,
responseText: error_response_403
});
moxios.stubRequest('https://worldcat.org/bib/data/404', {
status: 404,
responseText: error_response_404
});
let environment = "test";
const params = {
CiphertextBlob: fs.readFileSync(environment + "_config_encrypted.txt")
}
const kms = new AWS.KMS({'region': 'us-east-1'});
global.config = "";
function async startApp(){
try {
let data = await kms.decrypt(params).promise();
global.config = yaml.load(data['Plaintext'].toString());
let app = require('./src/server.js');
app.set('accessToken', accessToken);
let port = process.env.PORT || 8000;
// Server
app.listen(port, () => {
console.log(`Listening on: http://localhost:${port}`);
});
} catch (Error){
console.log(Error, Error.stack);
return Error;
}
}
startApp();