forked from Commit451/skyhook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
44 lines (40 loc) · 1.35 KB
/
test.ts
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
/**
* For running quick test things in node
*/
require('dotenv').config()
import axios from 'axios'
import * as fs from 'fs'
import { DiscordPayload } from './model/DiscordPayload'
import { AppVeyor } from './provider/Appveyor'
import { BaseProvider } from './provider/BaseProvider'
import { Heroku } from './provider/Heroku'
import { NewRelic } from './provider/NewRelic'
import { ErrorUtil } from './util/ErrorUtil'
testPayloadVisual(new Heroku(), 'heroku.json')
function testPayloadVisual(provider: BaseProvider, jsonFileName: string) {
const json = fs.readFileSync(`./test/${jsonFileName}`, 'utf-8')
provider.parse(JSON.parse(json)).then((discordPayload) => {
sendPayload(discordPayload)
}).catch((err) => {
console.log(err)
const payload = ErrorUtil.createErrorPayload(provider.getName(), err)
sendPayload(payload)
})
}
function sendPayload(discordPayload: DiscordPayload) {
const discordEndpoint = process.env.TEST_HOOK
if (discordEndpoint == null) {
console.log('Endpoint is null. You should set it to test out the payload visuals')
return
}
const jsonString = JSON.stringify(discordPayload)
axios({
data: jsonString,
method: 'post',
url: discordEndpoint
}).then(() => {
console.log('Sent')
}).catch((err: any) => {
console.log(err)
})
}