Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ikonst committed Jul 19, 2024
1 parent 43286d7 commit 4e9d23b
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions test/server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var fs = require('fs'),
assert = require('assert'),
axios = require('axios'),
soap = require('..');
const {log} = require("node:util");

var request = axios.default.create();
var lastReqAddress;
Expand Down Expand Up @@ -100,9 +101,14 @@ describe('SOAP Server', function () {
res.end();
});

test.logMessages = [];

test.server.listen(15099, null, null, function () {
var testSv = test.server.address();
test.soapServer = soap.listen(test.server, '/stockquote', test.service, test.wsdl);
test.soapServer.log = function (type, data, req) {
test.logMessages.push({ type, data, req });
};
test.baseUrl = `http://${testSv.address}:${testSv.port}`;

// windows return 0.0.0.0 as address and that is not valid to use in a request
Expand Down Expand Up @@ -208,6 +214,11 @@ describe('SOAP Server', function () {
assert.ok(err);
assert.equal(err.response.status, 500);
assert.ok(err.response.data.length);
const errorLog = test.logMessages.find(log => log.type === 'error');
assert.ok(errorLog);
assert(errorLog.data instanceof Error);
assert.ok(errorLog.data.name, 'TypeError');
assert.match(errorLog.data.stack, /TypeError: Cannot read properties of undefined \(reading 'description'\)/);
done();
});
});
Expand Down Expand Up @@ -241,6 +252,14 @@ describe('SOAP Server', function () {
assert.ok(err);
assert.equal(err.response.status, 500);
assert.ok(err.response.data.length);
const errorLog = test.logMessages.find(log => log.type === 'error');
assert.ok(errorLog);
assert.notStrictEqual(errorLog.data, {
faultcode: 500,
faultstring: 'Invalid XML',
detail: 'Error: Unexpected close tag\nLine: 0\nColumn: 184\nChar: >',
statusCode: undefined
});
done();
});
});
Expand Down Expand Up @@ -328,9 +347,8 @@ describe('SOAP Server', function () {
assert.ifError(err);
client.GetLastTradePrice({ tickerSymbol: 'Promise Error' }, function (err, response, body) {
assert.ok(err);
// what happens here (error and response ????)
// assert.strictEqual(err.response, response);
// assert.strictEqual(err.body, body);
assert.strictEqual(err.response, response);
assert.strictEqual(err.body, body);
done();
});
});
Expand Down Expand Up @@ -444,9 +462,11 @@ describe('SOAP Server', function () {
assert.ifError(err);
client.GetLastTradePrice({ tickerSymbol: 'trigger error' }, function (err, response, body) {
assert.ok(err);
// what happens here (error and response ????)
// assert.strictEqual(err.response, response);
// assert.strictEqual(err.body, body);
assert.strictEqual(err.response, response);
assert.strictEqual(err.body, body);
// console.log(test.logMessages);
// assert.strictEqual(test.logMessages.length, 1);
// assert.notStrictEqual(test.logMessages[0].tyoe, {});
done();
});
});
Expand Down

0 comments on commit 4e9d23b

Please sign in to comment.