Skip to content

Commit f824fc7

Browse files
author
Thomas Kgaevski
committed
fix async tests
1 parent 07cb1f5 commit f824fc7

3 files changed

Lines changed: 193 additions & 135 deletions

File tree

server/user-update.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ module.exports = function handle({ message = {} }, { ship, hull }) {
6464
logs.map(log => hull.logger.info("compute.console.log", { id: user.id, email: user.email, log }));
6565
}
6666
})
67-
.catch(err =>
67+
.catch(err => {
6868
console.log("error:", { err, message: err.message });
69-
hull.logger.error("compute.error", { err, user, segments })
70-
);
69+
hull.logger.error("compute.error", { err, user, segments });
70+
});
7171
};

tests/compute-account-tests.js

Lines changed: 78 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -37,82 +37,106 @@ function applyCompute(c) {
3737

3838
describe("Compute Ship for accounts", () => {
3939
describe("Compute method with accounts", () => {
40-
it("Should not change content if code does not change content", () => {
41-
const result = applyCompute(CODE.identity);
42-
expect(result.user).to.be.eql(user);
43-
expect(result.account).to.be.eql(account);
44-
expect(result.accountClaims).to.be.eql({});
40+
it("Should not change content if code does not change content", (done) => {
41+
applyCompute(CODE.identity).then(result => {
42+
expect(result.user).to.be.eql(user);
43+
expect(result.account).to.be.eql(account);
44+
expect(result.accountClaims).to.be.eql({});
45+
done();
46+
});
4547
});
4648

47-
it("Should set account claims", () => {
48-
const result = applyCompute(CODE.domain_claim);
49-
expect(result.user).to.be.eql(user);
50-
expect(result.changes).to.be.eql({ account: {}, user: {} });
51-
expect(result.accountClaims).to.be.eql({ domain: "google.com" });
49+
it("Should set account claims", (done) => {
50+
applyCompute(CODE.domain_claim).then(result => {
51+
expect(result.user).to.be.eql(user);
52+
expect(result.changes).to.be.eql({ account: {}, user: {} });
53+
expect(result.accountClaims).to.be.eql({ domain: "google.com" });
54+
done();
55+
});
5256
});
5357

54-
it("Should only add the correct number of entries and nothing else", () => {
55-
const result = applyCompute(CODE.one);
56-
expect(result.user).to.be.eql(user);
57-
expect(result.changes.user).to.be.eql({});
58-
expect(result.changes.account).to.deep.equal({ traits: { boom: "bam" }, domain: "test" });
58+
it("Should only add the correct number of entries and nothing else", (done) => {
59+
applyCompute(CODE.one).then(result => {
60+
expect(result.user).to.be.eql(user);
61+
expect(result.changes.user).to.be.eql({});
62+
expect(result.changes.account).to.deep.equal({ traits: { boom: "bam" }, domain: "test" });
63+
done();
64+
});
5965
});
6066

61-
it("Should add trait when code adds a trait", () => {
62-
const result = applyCompute(CODE.new_boolean);
63-
expect(result.user).to.be.eql(user);
64-
expect(result).to.have.deep.property("account.traits.new_boolean", true);
67+
it("Should add trait when code adds a trait", (done) => {
68+
applyCompute(CODE.new_boolean).then(result => {
69+
expect(result.user).to.be.eql(user);
70+
expect(result).to.have.deep.property("account.traits.new_boolean", true);
71+
done();
72+
});
6573
});
6674

67-
it("Should return grouped objects when groups are passed", () => {
68-
const result = applyCompute(CODE.group);
69-
expect(result.user).to.be.eql(user);
70-
expect(result).to.have.deep.property("account.group.line", "test");
75+
it("Should return grouped objects when groups are passed", (done) => {
76+
applyCompute(CODE.group).then(result => {
77+
expect(result.user).to.be.eql(user);
78+
expect(result).to.have.deep.property("account.group.line", "test");
79+
done();
80+
});
7181
});
7282

73-
it("Should return grouped objects when groups are passed", () => {
74-
const result = applyCompute(CODE.utils);
75-
expect(result.user).to.be.eql(user);
76-
expect(result).to.have.deep.property("changes.account.traits.hello_at", "20160101");
77-
expect(result).to.have.deep.property("changes.account.traits.host", "hull.io");
78-
expect(result).to.have.deep.property("changes.account.traits.keys", "a,b");
83+
it("Should return grouped objects when groups are passed", (done) => {
84+
applyCompute(CODE.utils).then(result => {
85+
expect(result.user).to.be.eql(user);
86+
expect(result).to.have.deep.property("changes.account.traits.hello_at", "20160101");
87+
expect(result).to.have.deep.property("changes.account.traits.host", "hull.io");
88+
expect(result).to.have.deep.property("changes.account.traits.keys", "a,b");
89+
done();
90+
});
7991
});
8092

81-
it("Should add an array element", () => {
82-
const result = applyCompute(CODE.add_array_element);
83-
expect(result.user).to.be.eql(user);
84-
expect(result.changes.account.traits.testing_array).to.deep.equal(["A", "B", "C", "E"]);
93+
it("Should add an array element", (done) => {
94+
applyCompute(CODE.add_array_element).then(result => {
95+
expect(result.user).to.be.eql(user);
96+
expect(result.changes.account.traits.testing_array).to.deep.equal(["A", "B", "C", "E"]);
97+
done();
98+
});
8599
});
86100

87-
it("Should modify an array element", () => {
88-
const result = applyCompute(CODE.modify_array_element);
89-
expect(result.user).to.be.eql(user);
90-
expect(result.changes.account.traits.testing_array).to.deep.equal(["F", "B", "C", "E"]);
101+
it("Should modify an array element", (done) => {
102+
applyCompute(CODE.modify_array_element).then(result => {
103+
expect(result.user).to.be.eql(user);
104+
expect(result.changes.account.traits.testing_array).to.deep.equal(["F", "B", "C", "E"]);
105+
done();
106+
});
91107
});
92108

93-
it("Should delete an array element", () => {
94-
const result = applyCompute(CODE.delete_array_element);
95-
expect(result.user).to.be.eql(user);
96-
expect(result.changes.account.traits.testing_array).to.deep.equal(["A", "B"]);
109+
it("Should delete an array element", (done) => {
110+
applyCompute(CODE.delete_array_element).then(result => {
111+
expect(result.user).to.be.eql(user);
112+
expect(result.changes.account.traits.testing_array).to.deep.equal(["A", "B"]);
113+
done();
114+
});
97115
});
98116

99-
it("Should change an array to string", () => {
100-
const result = applyCompute(CODE.array_to_string);
101-
expect(result.user).to.be.eql(user);
102-
expect(result.changes.account.traits.testing_array).to.equal("abcdef");
117+
it("Should change an array to string", (done) => {
118+
applyCompute(CODE.array_to_string).then(result => {
119+
expect(result.user).to.be.eql(user);
120+
expect(result.changes.account.traits.testing_array).to.equal("abcdef");
121+
done();
122+
});
103123
});
104124

105-
it("Should change a string to an array", () => {
106-
const result = applyCompute(CODE.string_to_array);
107-
expect(result.user).to.be.eql(user);
108-
expect(result.changes.account.traits.foo).to.deep.equal(["A", "B"]);
125+
it("Should change a string to an array", (done) => {
126+
applyCompute(CODE.string_to_array).then(result => {
127+
expect(result.user).to.be.eql(user);
128+
expect(result.changes.account.traits.foo).to.deep.equal(["A", "B"]);
129+
done();
130+
});
109131
});
110132

111-
it("Should change both user and account", () => {
112-
const result = applyCompute(CODE.user_and_account_traits);
113-
expect(result.accountClaims).to.eql({ domain: "facebook.com" });
114-
expect(result.changes.user).to.deep.equal({ traits: { age: 24 } });
115-
expect(result.changes.account).to.deep.equal({ traits: { country_code: "us" } });
133+
it("Should change both user and account", (done) => {
134+
applyCompute(CODE.user_and_account_traits).then(result => {
135+
expect(result.accountClaims).to.eql({ domain: "facebook.com" });
136+
expect(result.changes.user).to.deep.equal({ traits: { age: 24 } });
137+
expect(result.changes.account).to.deep.equal({ traits: { country_code: "us" } });
138+
done();
139+
});
116140
});
117141
});
118142
});

0 commit comments

Comments
 (0)