Skip to content

Commit 370cd7b

Browse files
authored
test: Updated unit test to match the API output (#33)
1 parent c0c33d0 commit 370cd7b

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

test/fixtures/update_user.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"action": "update",
33
"data": {
4-
"username": "3e21c60e-33ac-4242-aaf8-b04a089821c7",
4+
"username": "testName-3e21c60e-33ac-4242-aaf8-b04a089821c7",
55
"__entity_type__": "User",
66
"id": "8b0cabd6-2b93-4a6e-9aff-e163bea8844e",
77
"resource_type": "user"

test/session.test.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const credentials = {
2323
};
2424
let session = null;
2525

26+
function getTestUsername() {
27+
return `testName-${uuidV4()}`; // Use the same test user name format as the E2E tests. Simplifies cleanup if running the tests against a real server.
28+
}
29+
2630
beforeAll(() => {
2731
session = new Session(
2832
credentials.serverUrl,
@@ -62,7 +66,7 @@ describe("Session", () => {
6266

6367
it("Should allow creating a User", () => {
6468
const promise = session.create("User", {
65-
username: uuidV4(),
69+
username: getTestUsername(),
6670
});
6771

6872
return expect(
@@ -71,7 +75,7 @@ describe("Session", () => {
7175
});
7276

7377
it("Should allow deleting a User", async () => {
74-
const username = uuidV4();
78+
const username = getTestUsername();
7579
let promise = session.create("User", {
7680
username,
7781
});
@@ -88,24 +92,24 @@ describe("Session", () => {
8892
});
8993

9094
it("Should allow updating a User", async () => {
91-
const username = "new user";
92-
const newUsername = "3e21c60e-33ac-4242-aaf8-b04a089821c7";
95+
const username = getTestUsername();
96+
const shortUsername = username.slice(0, -30);
9397
let promise = session.create("User", {
94-
username,
98+
shortUsername,
9599
});
96100

97101
promise = promise.then((newUserResponse) => {
98102
const userId = newUserResponse.data.id;
99103
const updatePromise = session.update("User", userId, {
100-
username: newUsername,
104+
username: username,
101105
});
102106

103107
return updatePromise;
104108
});
105-
109+
// Checks a regex matching the username generated by getTestUsername()
106110
await expect(
107111
promise.then((response) => response.data.username)
108-
).resolves.toEqual(newUsername);
112+
).resolves.toMatch(/^testName-[0-9a-f-]{36}$/);
109113
});
110114

111115
it("Should support merging 0-level nested data", async () => {

0 commit comments

Comments
 (0)