Skip to content

Commit

Permalink
Update integration test for both clients
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Aug 15, 2023
1 parent d751739 commit 0a25bf4
Showing 1 changed file with 66 additions and 8 deletions.
74 changes: 66 additions & 8 deletions test/integration/client_headers_test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const http = require('http');
const url = require('url');
const http = require("http");
const url = require("url");
const port = 3100;

describe('integration tests: client headers', function (done) {
if (typeof window !== 'undefined') {
const versionPattern = /^[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+(\.[0-9])?)?$/;

describe("integration tests: client headers", function (done) {
if (typeof window !== "undefined") {
done();
return;
}
Expand All @@ -12,10 +14,8 @@ describe('integration tests: client headers', function (done) {
let server;

const requestHandler = (request, response) => {
expect(request.headers['x-client-name']).to.be.equal('js-soroban-client');
expect(request.headers['x-client-version']).to.match(
/^[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+(\.[0-9])?)?$/
);
expect(request.headers['x-client-name']).to.be.equal('js-stellar-sdk');
expect(request.headers['x-client-version']).to.match(versionPattern);
response.end();
server.close(() => done());
};
Expand All @@ -32,4 +32,62 @@ describe('integration tests: client headers', function (done) {
}).getHealth();
});
});

it("sends client via headers", function (done) {
let server;

const requestHandler = (request, response) => {
expect(request.headers["x-client-name"]).to.be.equal("js-stellar-sdk");
expect(request.headers["x-client-version"]).to.match(versionPattern);
response.end();
server.close(() => done());
};

server = http.createServer(requestHandler);
server.listen(port, (err) => {
if (err) {
done(err);
return;
}

new StellarSdk.Server(`http://localhost:${port}`, { allowHttp: true })
.operations()
.call();
});
});

it("sends client data via get params when streaming", function (done) {
let server;
let closeStream;

const requestHandler = (request, response) => {
// eslint-disable-next-line node/no-deprecated-api
let query = url.parse(request.url, true).query;
expect(query["X-Client-Name"]).to.be.equal("js-stellar-sdk");
expect(query["X-Client-Version"]).to.match(versionPattern);
response.end();
server.close(() => {
closeStream();
done();
});
};

server = http.createServer(requestHandler);
server.listen(port, (err) => {
if (err) {
done(err);
return;
}

closeStream = new StellarSdk.Server(`http://localhost:${port}`, {
allowHttp: true,
})
.operations()
.stream({
onerror: (err) => {
done(err);
},
});
});
});
});

0 comments on commit 0a25bf4

Please sign in to comment.