generated from bitprj/Intro-To-Serverless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.3.7.js
49 lines (40 loc) · 1.59 KB
/
test.3.7.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
let uri = undefined
const fetch = require('node-fetch');
const functions = require('./functions.js')
const args = require('minimist')(process.argv.slice(2))
const user = args['user'];
const repo = args['repo'];
async function main() {
try {
uri = process.env.DEEPSECRETS_ENDPOINT
functions.checkSecret(uri, "DEEPSECRETS_ENDPOINT")
const resp1 = await fetch(uri, {
method: 'POST',
body: "Body=testmessage2"
});
var result1 = await resp1.text()
functions.validateResponseStatus(resp1, uri)
const resp = await fetch(uri, {
method: 'POST',
body: "Body=testmessage3"
});
var result = await resp.text()
let test = JSON.stringify(result)
if (test.length < 3) {
console.error("No response... Try again!")
await functions.throwError("No response... Try again!", user, repo)
process.exit(1)
} else if (result == `Thanks 😊! Stored your secret "testmessage3". 😯 Someone confessed that: "testmessage2"`) {
console.info("Yay! 🎉 Thanks for returning our message from your database!")
} else {
console.error("Try again! We didn't get our most recent secret back.")
console.error(`We got "${result}", which is incorrect.`)
await functions.throwError(`Try again! We didn't get our most recent secret back. We got '${result}', which is incorrect.`, user, repo)
process.exit(1)
}
}
catch (e) {
await functions.throwError(e, user, repo)
}
}
main();