-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_request.test.js
More file actions
79 lines (73 loc) · 2.17 KB
/
http_request.test.js
File metadata and controls
79 lines (73 loc) · 2.17 KB
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
77
78
79
import assert from 'node:assert/strict'
import { loadEnvFile } from 'node:process'
import { describe, it } from 'node:test'
try {
loadEnvFile('.env')
} catch (error) {
if (error.code === 'ENOENT') {
console.log('No env file found, proceeding without it')
} else {
throw error
}
}
const { default: component } = await import('./http_request.js')
describe(component.name, () => {
it('should return error data (not throw an Error) when `throw_errors` is false', async (testContext) => {
if (!process.env.NETSUITE_CONFIG_DEV) {
testContext.skip('No NETSUITE_CONFIG_DEV env. var. found, so skipping integration test.')
return
}
component.config = process.env.NETSUITE_CONFIG_DEV
component.method = 'GET'
component.path = '/record/v1/customer/invalid-id-999'
component.headers = {}
component.get_more = false
component.skip = false
component.throw_errors = false
let response
try {
response = await component.run({
steps: {trigger: {}},
$: {
export: console.log
}
})
} catch (error) {
assert.fail(`An error was thrown (${error.message || error})`)
}
assert.ok(
response.error.length > 0,
'Did not find the expected error property.'
)
})
it('should throw an Error (not return error data) when `throw_errors` is true', async (testContext) => {
if (!process.env.NETSUITE_CONFIG_DEV) {
testContext.skip('No NETSUITE_CONFIG_DEV env. var. found, so skipping integration test.')
return
}
component.config = process.env.NETSUITE_CONFIG_DEV
component.method = 'GET'
component.path = '/record/v1/customer/invalid-id-999'
component.headers = {}
component.get_more = false
component.skip = false
component.throw_errors = true
let response
let thrownError
try {
response = await component.run({
steps: {trigger: {}},
$: {
export: console.log
}
})
} catch (error) {
thrownError = error
}
assert.ok(thrownError, 'Expected an error to be thrown')
assert.ok(
response?.error === undefined,
'Should not have returned error data'
)
})
})