Skip to content

Commit

Permalink
Merge branch 'release/3.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
dhenl2 committed Jun 3, 2024
2 parents ff284bd + b4898ff commit 6a07e07
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 16 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [3.1.1] - 2024-06-03
### CHANGED
- The `http` option `keepAlive` will now default to `true` if it is not specified.

#### FIXED
- `WideSkyClient.batch.updateOrCreate` errored with list type tags.

## [3.1.0] - 2024-05-23
### ADDED
- Added new [options](./docs/client/options.md) under `http` which allows an optional configuration
Expand Down Expand Up @@ -206,7 +213,7 @@ duplicated, even in the case where a package's version was unpublished. This is
### ADDED
- Alpha release

[Unreleased]: https://github.com/widesky/jswidesky-client/compare/master...3.1.0
[Unreleased]: https://github.com/widesky/jswidesky-client/compare/master...3.1.1
[1.0.0]: https://github.com/widesky/jswidesky-client/compare/1.0.0...1.0.0
[1.1.0]: https://github.com/widesky/jswidesky-client/compare/1.1.0...1.0.0
[1.1.1]: https://github.com/widesky/jswidesky-client/compare/1.1.1...1.1.0
Expand All @@ -230,3 +237,4 @@ duplicated, even in the case where a package's version was unpublished. This is
[3.0.0]: https://github.com/widesky/jswidesky-client/compare/3.0.0...2.1.5
[3.0.1]: https://github.com/widesky/jswidesky-client/compare/3.0.1...3.0.0
[3.1.0]: https://github.com/widesky/jswidesky-client/compare/3.1.0...3.0.1
[3.1.0]: https://github.com/widesky/jswidesky-client/compare/3.1.1...3.1.0
33 changes: 30 additions & 3 deletions dist/jsWideSky.develop.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jsWideSky.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@widesky/jswidesky-client",
"version": "3.1.0",
"version": "3.1.1",
"description": "WideSky Client in JavaScript",
"main": "index.js",
"private": false,
Expand Down
15 changes: 13 additions & 2 deletions src/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,19 @@ class WideSkyClient {
* Apply the config to be used for all axios requests.
*/
initAxios() {
this.httpAgent = new http.Agent(this.options?.http || {});
this.httpsAgent = new https.Agent(this.options?.http || {});
// If HTTP options keepAlive is undefined, default it to true.
if (typeof this.options.http === 'object') {
if (this.options.http.keepAlive === undefined) {
this.options.http.keepAlive = true; // default to true
}
} else {
this.options.http = {
keepAlive: true // default to true
};
}

this.httpAgent = new http.Agent(this.options.http);
this.httpsAgent = new https.Agent(this.options.http);

this.axios = axios.create(Object.assign({
baseURL: this.baseUri,
Expand Down
20 changes: 19 additions & 1 deletion src/client/functions/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,24 @@ const createUpdatePayload = (oldEntity, newEntity, logger) => {

if (oldEntity[tag] === undefined) {
updatePayload[tag] = value;
} else if (Array.isArray(value) && Array.isArray(oldEntity[tag])) {
if (value.length !== oldEntity[tag].length) {
// Not the same, no need to verify
updatePayload[tag] = value;
}

// verify list changes
let isDifferent = false;
for (const item of value) {
if (!(oldEntity[tag].includes(item))) {
isDifferent = true;
break;
}
}

if (isDifferent) {
updatePayload[tag] = value;
}
} else if (oldEntity[tag] !== value) {
if (tag.includes("Ref") || ["metaOf"].includes(tag)) {
// Ref can be different by the ID is what matters here
Expand Down Expand Up @@ -1237,4 +1255,4 @@ module.exports = {
addChildrenByFilter,
multiFind,
updateOrCreate
};
};
66 changes: 64 additions & 2 deletions test/client/functions/batch/updateOrCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("client.batch.updateOrCreate", () => {
success: TEST_ENTITIES.map((entity) => [entity]),
errors: []
};
})
});
ws.batch.create = sinon.stub().callsFake((entities) => {
return {
success: {
Expand Down Expand Up @@ -254,6 +254,68 @@ describe("client.batch.updateOrCreate", () => {
});
});

describe("tag types", () => {
describe("list tag", () => {
beforeEach(() => {
const testEntities = JSON.parse(JSON.stringify(TEST_ENTITIES));
testEntities[0].roleRefs = ["r:id1", "r:id2", "r:id3"];
ws.batch.multiFind = sinon.stub().callsFake((filterAndLimits) => {
return {
success: testEntities.map((entity) => [entity]),
errors: []
};
});
});

it("should not update if the list is the same", async () => {
const testEntities = JSON.parse(JSON.stringify(TEST_ENTITIES));
testEntities[0].roleRefs = ["r:id1", "r:id2", "r:id3"];
await ws.batch.updateOrCreate(testEntities);
expect(ws.batch.create.notCalled).to.be.true;
expect(ws.batch.update.notCalled).to.be.true;
});

it("should not update if the list is the same but different order", async () => {
const testEntities = JSON.parse(JSON.stringify(TEST_ENTITIES));
testEntities[0].roleRefs = ["r:id3", "r:id2", "r:id1"];
await ws.batch.updateOrCreate(testEntities);
expect(ws.batch.create.notCalled).to.be.true;
expect(ws.batch.update.notCalled).to.be.true;
});

it("should update if list different sizes", async () => {
const testEntities = JSON.parse(JSON.stringify(TEST_ENTITIES));
testEntities[0].roleRefs = ["r:id2", "r:id1"];
await ws.batch.updateOrCreate(testEntities);
expect(ws.batch.create.notCalled).to.be.true;
expect(ws.batch.update.calledOnce).to.be.true;
expect(ws.batch.update.getCall(0).args[0]).to.eql([{
"id": "r:fbf5ace2-b706-11ec-a270-0242ac120002",
"roleRefs": [
"r:id2",
"r:id1"
]
}]);
});

it("should update if list has 1 item that is different", async () => {
const testEntities = JSON.parse(JSON.stringify(TEST_ENTITIES));
testEntities[0].roleRefs = ["r:id2", "r:id1", "r:id4"];
await ws.batch.updateOrCreate(testEntities);
expect(ws.batch.create.notCalled).to.be.true;
expect(ws.batch.update.calledOnce).to.be.true;
expect(ws.batch.update.getCall(0).args[0]).to.eql([{
"id": "r:fbf5ace2-b706-11ec-a270-0242ac120002",
"roleRefs": [
"r:id2",
"r:id1",
"r:id4"
]
}]);
});
});
});

describe("options", () => {
it("should pass to client.batch.update", async () => {
const testEntities = JSON.parse(JSON.stringify(TEST_ENTITIES));
Expand Down Expand Up @@ -440,4 +502,4 @@ describe("client.batch.updateOrCreate", () => {
});
});
});
});
});
29 changes: 26 additions & 3 deletions test/client/internals/initAxios.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ describe("client", () => {
expect(passedAxiosOptions.baseURL).to.equal(stubs.WS_URI);

expect(passedAxiosOptions.httpAgent instanceof http.Agent).to.be.true;
expect(passedAxiosOptions.httpAgent.keepAlive).to.eql(false);
expect(passedAxiosOptions.httpAgent.keepAlive).to.eql(true);
expect(passedAxiosOptions.httpAgent.keepAliveMsecs).to.eql(1000);

expect(passedAxiosOptions.httpsAgent instanceof https.Agent).to.be.true;
expect(passedAxiosOptions.httpsAgent.keepAlive).to.eql(false);
expect(passedAxiosOptions.httpsAgent.keepAlive).to.eql(true);
expect(passedAxiosOptions.httpsAgent.keepAliveMsecs).to.eql(1000);
});

Expand All @@ -56,7 +56,30 @@ describe("client", () => {
test: 123
},
http: {
keepAlive: true,
keepAlive: false,
keepAliveMsecs: 2000
}
};
ws.initAxios();
expect(Object.keys(passedAxiosOptions).length).to.equal(4);
expect(passedAxiosOptions.baseURL).to.equal(stubs.WS_URI);
expect(passedAxiosOptions.test).to.equal(123);

expect(passedAxiosOptions.httpAgent instanceof http.Agent).to.be.true;
expect(passedAxiosOptions.httpAgent.keepAlive).to.eql(false);
expect(passedAxiosOptions.httpAgent.keepAliveMsecs).to.eql(2000);

expect(passedAxiosOptions.httpsAgent instanceof https.Agent).to.be.true;
expect(passedAxiosOptions.httpsAgent.keepAlive).to.eql(false);
expect(passedAxiosOptions.httpsAgent.keepAliveMsecs).to.eql(2000);
});

it("should set keepAlive=true if not specified", () => {
ws.options = {
axios: {
test: 123
},
http: {
keepAliveMsecs: 2000
}
};
Expand Down

0 comments on commit 6a07e07

Please sign in to comment.