Skip to content

test: Updated unit test to match the API output #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/fixtures/update_user.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"action": "update",
"data": {
"username": "3e21c60e-33ac-4242-aaf8-b04a089821c7",
"username": "testName-3e21c60e-33ac-4242-aaf8-b04a089821c7",
"__entity_type__": "User",
"id": "8b0cabd6-2b93-4a6e-9aff-e163bea8844e",
"resource_type": "user"
Expand Down
20 changes: 12 additions & 8 deletions test/session.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const credentials = {
};
let session = null;

function getTestUsername() {
return `testName-${uuidV4()}`; // Use the same test user name format as the E2E tests. Simplifies cleanup if running the tests against a real server.
}

beforeAll(() => {
session = new Session(
credentials.serverUrl,
Expand Down Expand Up @@ -62,7 +66,7 @@ describe("Session", () => {

it("Should allow creating a User", () => {
const promise = session.create("User", {
username: uuidV4(),
username: getTestUsername(),
});

return expect(
Expand All @@ -71,7 +75,7 @@ describe("Session", () => {
});

it("Should allow deleting a User", async () => {
const username = uuidV4();
const username = getTestUsername();
let promise = session.create("User", {
username,
});
Expand All @@ -88,24 +92,24 @@ describe("Session", () => {
});

it("Should allow updating a User", async () => {
const username = "new user";
const newUsername = "3e21c60e-33ac-4242-aaf8-b04a089821c7";
const username = getTestUsername();
const shortUsername = username.slice(0, -30);
let promise = session.create("User", {
username,
shortUsername,
});

promise = promise.then((newUserResponse) => {
const userId = newUserResponse.data.id;
const updatePromise = session.update("User", userId, {
username: newUsername,
username: username,
});

return updatePromise;
});

// Checks a regex matching the username generated by getTestUsername()
await expect(
promise.then((response) => response.data.username)
).resolves.toEqual(newUsername);
).resolves.toMatch(/^testName-[0-9a-f-]{36}$/);
});

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