Skip to content

Commit 1b451ca

Browse files
authored
fix(api): ensure balance is captured as number of cents when user account created (#1544)
1 parent 563baf8 commit 1b451ca

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

backend/database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export const createUser = (userDetails: Partial<User>): User => {
186186
password,
187187
email: userDetails.email!,
188188
phoneNumber: userDetails.phoneNumber!,
189-
balance: userDetails.balance! || 0,
189+
balance: Number(userDetails.balance!) || 0,
190190
avatar: userDetails.avatar!,
191191
defaultPrivacyLevel: userDetails.defaultPrivacyLevel!,
192192
createdAt: new Date(),

cypress/tests/api/api-users.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,25 @@ describe("Users API", function () {
135135
});
136136
});
137137

138+
it("creates a new user with an account balance in cents", function () {
139+
const firstName = faker.name.firstName();
140+
141+
cy.request("POST", `${apiUsers}`, {
142+
firstName,
143+
lastName: faker.name.lastName(),
144+
username: faker.internet.userName(),
145+
password: faker.internet.password(),
146+
email: faker.internet.email(),
147+
phoneNumber: faker.phone.phoneNumber(),
148+
avatar: faker.internet.avatar(),
149+
balance: 100_00,
150+
}).then((response) => {
151+
expect(response.status).to.eq(201);
152+
expect(response.body.user).to.contain({ firstName });
153+
expect(response.body.user.balance).to.equal(100_00);
154+
});
155+
});
156+
138157
it("error when invalid field sent", function () {
139158
cy.request({
140159
method: "POST",

0 commit comments

Comments
 (0)