Skip to content

Commit

Permalink
Sort selected keys alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
johantell committed Dec 27, 2016
1 parent 6eebb56 commit 8f2a947
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = class ExpPipelineMap extends Promise {
return this.then((object) => {
const targetObject = {};

properties.filter((property) => object.hasOwnProperty(property))
properties.sort().filter((property) => object.hasOwnProperty(property))
.forEach((property) => {
targetObject[property] = object[property];
});
Expand Down
21 changes: 20 additions & 1 deletion test/expPipelineMapTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ describe("mapperHelper", () => {
expect(Mapper.transform(sourceObject).select([])).to.be.an.instanceof(Mapper);
});

it("sorts the properties alphabetically", () => {
return Mapper.transform(sourceObject)
.select("one", "two", "three")
.then((response) => {
expect(Object.keys(response)).to.eql(["one", "three", "two"]);
})
});

it("Selects properties", () => {
const result = {one: 1, three: 3};
return Mapper.transform(sourceObject)
Expand Down Expand Up @@ -84,10 +92,21 @@ describe("mapperHelper", () => {
const result = { one: 1, two: 2 };
return Mapper.transform(sourceObject)
.add("two", new Promise((r) => {
setTimeout(() => r(2), 4);
setTimeout(() => r(2), 0);
}))
.then((object) => expect(object).to.eql(result));
});

it("handles creation of property by function that returns a promise", () => {
const result = { one: 1, two: 2 };
return Mapper.transform(sourceObject)
.add("two", () => {
return new Promise((r) => {
setTimeout(() => r(2), 0);
});
})
.then((object) => expect(object).to.eql(result));
});
});

context("#transform", () => {
Expand Down

0 comments on commit 8f2a947

Please sign in to comment.