Skip to content

Commit 7aae84f

Browse files
committed
Added request to get JWT token and fixed breakpoint test
1 parent 93f9a36 commit 7aae84f

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

test/test.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
const host = "http://localhost:12800";
2-
const SYSTEM_JWT_TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJkZXZlbG9wZXJfaWQiOiJzeXN0ZW0iLCJjcmVhdGVkX2F0IjoxNjU4NzM3Njc5NTIxLCJleHBpcmVzX2F0IjoxNjkwMjczNjc5NTIxLCJpYXQiOjE2NTg3Mzc2Nzl9.C70FjmmhLoG38x5LWa9LuzTMs1YnP0DRMfZxVuzBa6OzEp-dEvGIS5Y_k7LiZSRqjgXyaUGpXnDXzOUPigrpwj7Fx_IYrgkOwuw5l-Wv4hasI-RYQjx5MZLa-dmw_ObY8_AOHF_XNuElPVSKpKMpN6THRT2IfelXKz6OINgZr4pQzqgFlc4KnVhB87Rm9Ya-KbxvzREicp5mmVGo2Ca4_nf7SyM5ZLP1vYw4FOt_Eejioub859q-CCL1ZqwvPb3Kwmzga3USLyAzlk_R4vYZWDyZmq0qiOTBO2V97GleXbl8b4Xiw3Uxwlc76svDefNNH0VLtWM-mOPhRNnUPiUbcQHxNTCTuHF6jEhvvVbKaq5welGkINF7HLX7zGxcYwylsz6UVNa3c-LX89wfQbKlGr9pERJSwCvNtTMHq7oj_xI99e4A1cw7DX8LjAnp9zrUZgpo7OVT_TEVFXKtNQtKlKn6Pg48y6sFE3Wf48An6A5cIzrgHjfyOq1NWbDrQMon4acD_jPwcFYn21Or2YULRBRQR7hQCGBvkoIo5t24e-5ELm9h5PTcDeDLndKsik8DjzhPuLIqU9_gM0WMrr5sC0nh5eR2GMKfedcKULUU5Ql3Y_3Q0_hUx-wQ8ZT2LJez6bZF6vSgr9E6d6QpL5tfIg4vbsDYj-yqdhzB4R7XvUQ"
32
const assert = require('assert');
43
const {default: axios} = require("axios");
54

5+
const tokenPromise = axios.get(`${host}/api/new-token?access_token=change-me`)
6+
.then(response => response.data);
7+
68
describe('Stats', function () {
79
let response;
810
describe('/stats', function () {
9-
before(function () {
11+
before(async function () {
1012
return axios.get(`${host}/stats`, {
11-
headers: {Authorization: 'Bearer ' + SYSTEM_JWT_TOKEN}
13+
headers: {Authorization: 'Bearer ' + await tokenPromise}
1214
}).then(function (res) {
1315
response = res;
1416
})
@@ -19,6 +21,7 @@ describe('Stats', function () {
1921
})
2022

2123
it('probe is connected', function () {
24+
console.log(response.data);
2225
assert.equal(
2326
response.data.platform["connected-probes"],
2427
1
@@ -37,9 +40,9 @@ describe('Stats', function () {
3740
describe('Clients', function () {
3841
let response;
3942
describe('/clients', function () {
40-
before(function () {
43+
before(async function () {
4144
return axios.get(`${host}/clients`, {
42-
headers: {Authorization: 'Bearer ' + SYSTEM_JWT_TOKEN}
45+
headers: {Authorization: 'Bearer ' + await tokenPromise}
4346
}).then(function (res) {
4447
response = res;
4548
})
@@ -134,20 +137,20 @@ describe('NodeJS Probe', function () {
134137
let response;
135138

136139
describe("connect test probe to platform", function () {
137-
before(function () {
138-
return SourcePlusPlus.start().then(function (spp) {
140+
before(async function () {
141+
return SourcePlusPlus.start().then(function () {
139142
console.log("SourcePlusPlus started");
140143
}).catch(function (err) {
141144
assert.fail(err);
142145
});
143146
});
144-
after(function () {
147+
after(async function () {
145148
return SourcePlusPlus.stop();
146149
});
147150

148-
it('add live breakpoint', function () {
149-
addLiveBreakpoint({
150-
"source": "test.js",
151+
it('add live breakpoint', async function () {
152+
await addLiveBreakpoint({
153+
"source": "test/test.js",
151154
"line": 10
152155
}, 20).then(function (res) {
153156
assert.equal(res.status, 200);
@@ -161,7 +164,7 @@ describe('NodeJS Probe', function () {
161164
this.timeout(6000)
162165

163166
setTimeout(function () {
164-
assert.equal(SourcePlusPlus.liveInstrumentRemote.instrumentCache.size, 1);
167+
assert.equal(SourcePlusPlus.liveInstrumentRemote.instruments.size, 1);
165168
done();
166169
}, 5000);
167170
});
@@ -185,13 +188,13 @@ describe('NodeJS Probe', function () {
185188
});
186189
});
187190

188-
function addLiveBreakpoint(location, hitLimit) {
191+
async function addLiveBreakpoint(location, hitLimit) {
189192
const options = {
190193
method: 'POST',
191194
url: `${host}/graphql/spp`,
192195
headers: {
193196
'Content-Type': 'application/json',
194-
Authorization: 'Bearer ' + SYSTEM_JWT_TOKEN
197+
Authorization: 'Bearer ' + await tokenPromise
195198
},
196199
data: {
197200
"query": "mutation ($input: LiveBreakpointInput!) { addLiveBreakpoint(input: $input) { id location { source line } condition expiresAt hitLimit applyImmediately applied pending throttle { limit step } } }",
@@ -206,13 +209,13 @@ function addLiveBreakpoint(location, hitLimit) {
206209
return axios.request(options);
207210
}
208211

209-
function removeLiveInstrument(id) {
212+
async function removeLiveInstrument(id) {
210213
const options = {
211214
method: 'POST',
212215
url: `${host}/graphql/spp`,
213216
headers: {
214217
'Content-Type': 'application/json',
215-
Authorization: 'Bearer ' + SYSTEM_JWT_TOKEN
218+
Authorization: 'Bearer ' + await tokenPromise
216219
},
217220
data: {
218221
"query": "mutation ($id: String!) { removeLiveInstrument(id: $id) { id } }",

0 commit comments

Comments
 (0)