Skip to content

Commit

Permalink
fix(api): ensure balance is captured as number of cents when user acc…
Browse files Browse the repository at this point in the history
…ount created (#1544)
  • Loading branch information
jan-molak authored Apr 16, 2024
1 parent 563baf8 commit 1b451ca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const createUser = (userDetails: Partial<User>): User => {
password,
email: userDetails.email!,
phoneNumber: userDetails.phoneNumber!,
balance: userDetails.balance! || 0,
balance: Number(userDetails.balance!) || 0,
avatar: userDetails.avatar!,
defaultPrivacyLevel: userDetails.defaultPrivacyLevel!,
createdAt: new Date(),
Expand Down
19 changes: 19 additions & 0 deletions cypress/tests/api/api-users.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,25 @@ describe("Users API", function () {
});
});

it("creates a new user with an account balance in cents", function () {
const firstName = faker.name.firstName();

cy.request("POST", `${apiUsers}`, {
firstName,
lastName: faker.name.lastName(),
username: faker.internet.userName(),
password: faker.internet.password(),
email: faker.internet.email(),
phoneNumber: faker.phone.phoneNumber(),
avatar: faker.internet.avatar(),
balance: 100_00,
}).then((response) => {
expect(response.status).to.eq(201);
expect(response.body.user).to.contain({ firstName });
expect(response.body.user.balance).to.equal(100_00);
});
});

it("error when invalid field sent", function () {
cy.request({
method: "POST",
Expand Down

0 comments on commit 1b451ca

Please sign in to comment.