feat: add async suffix eslint rule (#485)

This commit is contained in:
Manuel
2024-05-18 12:25:33 +02:00
committed by GitHub
parent 5723295856
commit dcaff1d91c
60 changed files with 296 additions and 225 deletions

View File

@@ -78,8 +78,8 @@ describe("byId should return an app by id", () => {
session: null,
});
const act = async () => await caller.byId({ id: "2" });
await expect(act()).rejects.toThrow("App not found");
const actAsync = async () => await caller.byId({ id: "2" });
await expect(actAsync()).rejects.toThrow("App not found");
});
});
@@ -174,7 +174,7 @@ describe("update should update an app", () => {
session: null,
});
const act = async () =>
const actAsync = async () =>
await caller.update({
id: createId(),
name: "Mantine",
@@ -182,7 +182,7 @@ describe("update should update an app", () => {
description: null,
href: null,
});
await expect(act()).rejects.toThrow("App not found");
await expect(actAsync()).rejects.toThrow("App not found");
});
});

View File

@@ -37,7 +37,7 @@ const defaultSession = {
// Mock the auth module to return an empty session
vi.mock("@homarr/auth", () => ({ auth: () => ({}) as Session }));
const createRandomUser = async (db: Database) => {
const createRandomUserAsync = async (db: Database) => {
const userId = createId();
await db.insert(users).values({
id: userId,
@@ -51,8 +51,8 @@ describe("getAllBoards should return all boards accessable to the current user",
const db = createDb();
const caller = boardRouter.createCaller({ db, session: null });
const user1 = await createRandomUser(db);
const user2 = await createRandomUser(db);
const user1 = await createRandomUserAsync(db);
const user2 = await createRandomUserAsync(db);
await db.insert(boards).values([
{
@@ -91,8 +91,8 @@ describe("getAllBoards should return all boards accessable to the current user",
},
});
const user1 = await createRandomUser(db);
const user2 = await createRandomUser(db);
const user1 = await createRandomUserAsync(db);
const user2 = await createRandomUserAsync(db);
await db.insert(boards).values([
{
@@ -122,8 +122,8 @@ describe("getAllBoards should return all boards accessable to the current user",
const db = createDb();
const caller = boardRouter.createCaller({ db, session: defaultSession });
const user1 = await createRandomUser(db);
const user2 = await createRandomUser(db);
const user1 = await createRandomUserAsync(db);
const user2 = await createRandomUserAsync(db);
await db.insert(users).values({
id: defaultCreatorId,
});
@@ -170,8 +170,8 @@ describe("getAllBoards should return all boards accessable to the current user",
session: defaultSession,
});
const user1 = await createRandomUser(db);
const user2 = await createRandomUser(db);
const user1 = await createRandomUserAsync(db);
const user2 = await createRandomUserAsync(db);
await db.insert(users).values({
id: defaultCreatorId,
});
@@ -237,8 +237,8 @@ describe("getAllBoards should return all boards accessable to the current user",
session: defaultSession,
});
const user1 = await createRandomUser(db);
const user2 = await createRandomUser(db);
const user1 = await createRandomUserAsync(db);
const user2 = await createRandomUserAsync(db);
await db.insert(users).values({
id: defaultCreatorId,
});
@@ -322,10 +322,10 @@ describe("createBoard should create a new board", () => {
const caller = boardRouter.createCaller({ db, session: defaultSession });
// Act
const act = async () => await caller.createBoard({ name: "newBoard" });
const actAsync = async () => await caller.createBoard({ name: "newBoard" });
// Assert
await expect(act()).rejects.toThrowError("Permission denied");
await expect(actAsync()).rejects.toThrowError("Permission denied");
});
});
@@ -383,11 +383,11 @@ describe("rename board should rename board", () => {
});
// Act
const act = async () =>
const actAsync = async () =>
await caller.renameBoard({ id: boardId, name: "Newname" });
// Assert
await expect(act()).rejects.toThrowError(
await expect(actAsync()).rejects.toThrowError(
"Board with similar name already exists",
);
});
@@ -398,11 +398,11 @@ describe("rename board should rename board", () => {
const caller = boardRouter.createCaller({ db, session: defaultSession });
// Act
const act = async () =>
const actAsync = async () =>
await caller.renameBoard({ id: "nonExistentBoardId", name: "newName" });
// Assert
await expect(act()).rejects.toThrowError("Board not found");
await expect(actAsync()).rejects.toThrowError("Board not found");
});
});
@@ -485,11 +485,11 @@ describe("deleteBoard should delete board", () => {
const caller = boardRouter.createCaller({ db, session: defaultSession });
// Act
const act = async () =>
const actAsync = async () =>
await caller.deleteBoard({ id: "nonExistentBoardId" });
// Assert
await expect(act()).rejects.toThrowError("Board not found");
await expect(actAsync()).rejects.toThrowError("Board not found");
});
});
@@ -552,11 +552,11 @@ describe("getBoardByName should return board by name", () => {
await createFullBoardAsync(db, "default");
// Act
const act = async () =>
const actAsync = async () =>
await caller.getBoardByName({ name: "nonExistentBoard" });
// Assert
await expect(act()).rejects.toThrowError("Board not found");
await expect(actAsync()).rejects.toThrowError("Board not found");
});
});
@@ -633,7 +633,7 @@ describe("savePartialBoardSettings should save general settings", () => {
const db = createDb();
const caller = boardRouter.createCaller({ db, session: defaultSession });
const act = async () =>
const actAsync = async () =>
await caller.savePartialBoardSettings({
pageTitle: "newPageTitle",
metaTitle: "newMetaTitle",
@@ -642,7 +642,7 @@ describe("savePartialBoardSettings should save general settings", () => {
id: "nonExistentBoardId",
});
await expect(act()).rejects.toThrowError("Board not found");
await expect(actAsync()).rejects.toThrowError("Board not found");
});
});
@@ -1151,13 +1151,13 @@ describe("saveBoard should save full board", () => {
const db = createDb();
const caller = boardRouter.createCaller({ db, session: defaultSession });
const act = async () =>
const actAsync = async () =>
await caller.saveBoard({
id: "nonExistentBoardId",
sections: [],
});
await expect(act()).rejects.toThrowError("Board not found");
await expect(actAsync()).rejects.toThrowError("Board not found");
});
});
@@ -1168,8 +1168,8 @@ describe("getBoardPermissions should return board permissions", () => {
const caller = boardRouter.createCaller({ db, session: defaultSession });
const spy = vi.spyOn(boardAccess, "throwIfActionForbiddenAsync");
const user1 = await createRandomUser(db);
const user2 = await createRandomUser(db);
const user1 = await createRandomUserAsync(db);
const user2 = await createRandomUserAsync(db);
await db.insert(users).values({
id: defaultCreatorId,
});
@@ -1250,7 +1250,7 @@ describe("saveUserBoardPermissions should save user board permissions", () => {
const caller = boardRouter.createCaller({ db, session: defaultSession });
const spy = vi.spyOn(boardAccess, "throwIfActionForbiddenAsync");
const user1 = await createRandomUser(db);
const user1 = await createRandomUserAsync(db);
await db.insert(users).values({
id: defaultCreatorId,
});

View File

@@ -9,7 +9,10 @@ import { throwIfActionForbiddenAsync } from "../../board/board-access";
const defaultCreatorId = createId();
const expectActToBe = async (act: () => Promise<void>, success: boolean) => {
const expectActToBeAsync = async (
act: () => Promise<void>,
success: boolean,
) => {
if (!success) {
await expect(act()).rejects.toThrow("Board not found");
return;
@@ -55,7 +58,7 @@ describe("throwIfActionForbiddenAsync should check access to board and return bo
);
// Assert
await expectActToBe(act, expectedResult);
await expectActToBeAsync(act, expectedResult);
},
);
@@ -92,7 +95,7 @@ describe("throwIfActionForbiddenAsync should check access to board and return bo
);
// Assert
await expectActToBe(act, expectedResult);
await expectActToBeAsync(act, expectedResult);
},
);
@@ -129,7 +132,7 @@ describe("throwIfActionForbiddenAsync should check access to board and return bo
);
// Assert
await expectActToBe(act, expectedResult);
await expectActToBeAsync(act, expectedResult);
},
);
@@ -166,7 +169,7 @@ describe("throwIfActionForbiddenAsync should check access to board and return bo
);
// Assert
await expectActToBe(act, expectedResult);
await expectActToBeAsync(act, expectedResult);
},
);

View File

@@ -196,10 +196,10 @@ describe("byId should return group by id including members and permissions", ()
});
// Act
const act = async () => await caller.getById({ id: "1" });
const actAsync = async () => await caller.getById({ id: "1" });
// Assert
await expect(act()).rejects.toThrow("Group not found");
await expect(actAsync()).rejects.toThrow("Group not found");
});
});
@@ -235,13 +235,13 @@ describe("create should create group in database", () => {
const longName = "a".repeat(65);
// Act
const act = async () =>
const actAsync = async () =>
await caller.createGroup({
name: longName,
});
// Assert
await expect(act()).rejects.toThrow("too_big");
await expect(actAsync()).rejects.toThrow("too_big");
});
test.each([
@@ -262,10 +262,11 @@ describe("create should create group in database", () => {
});
// Act
const act = async () => await caller.createGroup({ name: nameToCreate });
const actAsync = async () =>
await caller.createGroup({ name: nameToCreate });
// Assert
await expect(act()).rejects.toThrow("similar name");
await expect(actAsync()).rejects.toThrow("similar name");
},
);
});
@@ -330,14 +331,14 @@ describe("update should update name with value that is no duplicate", () => {
]);
// Act
const act = async () =>
const actAsync = async () =>
await caller.updateGroup({
id: groupId,
name: updateValue,
});
// Assert
await expect(act()).rejects.toThrow("similar name");
await expect(actAsync()).rejects.toThrow("similar name");
},
);
@@ -408,14 +409,14 @@ describe("savePermissions should save permissions for group", () => {
});
// Act
const act = async () =>
const actAsync = async () =>
await caller.savePermissions({
groupId: createId(),
permissions: ["integration-create", "board-full-access"],
});
// Assert
await expect(act()).rejects.toThrow("Group not found");
await expect(actAsync()).rejects.toThrow("Group not found");
});
});
@@ -468,14 +469,14 @@ describe("transferOwnership should transfer ownership of group", () => {
});
// Act
const act = async () =>
const actAsync = async () =>
await caller.transferOwnership({
groupId: createId(),
userId: createId(),
});
// Assert
await expect(act()).rejects.toThrow("Group not found");
await expect(actAsync()).rejects.toThrow("Group not found");
});
});
@@ -520,13 +521,13 @@ describe("deleteGroup should delete group", () => {
});
// Act
const act = async () =>
const actAsync = async () =>
await caller.deleteGroup({
id: createId(),
});
// Assert
await expect(act()).rejects.toThrow("Group not found");
await expect(actAsync()).rejects.toThrow("Group not found");
});
});
@@ -580,14 +581,14 @@ describe("addMember should add member to group", () => {
});
// Act
const act = async () =>
const actAsync = async () =>
await caller.addMember({
groupId: createId(),
userId: createId(),
});
// Assert
await expect(act()).rejects.toThrow("Group not found");
await expect(actAsync()).rejects.toThrow("Group not found");
});
});
@@ -644,14 +645,14 @@ describe("removeMember should remove member from group", () => {
});
// Act
const act = async () =>
const actAsync = async () =>
await caller.removeMember({
groupId: createId(),
userId: createId(),
});
// Assert
await expect(act()).rejects.toThrow("Group not found");
await expect(actAsync()).rejects.toThrow("Group not found");
});
});

View File

@@ -76,8 +76,8 @@ describe("byId should return an integration by id", () => {
session: null,
});
const act = async () => await caller.byId({ id: "2" });
await expect(act()).rejects.toThrow("Integration not found");
const actAsync = async () => await caller.byId({ id: "2" });
await expect(actAsync()).rejects.toThrow("Integration not found");
});
it("should only return the public secret values", async () => {
@@ -258,14 +258,14 @@ describe("update should update an integration", () => {
session: null,
});
const act = async () =>
const actAsync = async () =>
await caller.update({
id: createId(),
name: "Pi Hole",
url: "http://hole.local",
secrets: [],
});
await expect(act()).rejects.toThrow("Integration not found");
await expect(actAsync()).rejects.toThrow("Integration not found");
});
});
@@ -343,8 +343,8 @@ describe("testConnection should test the connection to an integration", () => {
secrets,
};
const act = async () => await caller.testConnection(input);
await expect(act()).rejects.toThrow("SECRETS_NOT_DEFINED");
const actAsync = async () => await caller.testConnection(input);
await expect(actAsync()).rejects.toThrow("SECRETS_NOT_DEFINED");
},
);
@@ -373,8 +373,8 @@ describe("testConnection should test the connection to an integration", () => {
secrets,
};
const act = async () => await caller.testConnection(input);
await expect(act()).resolves.toBeUndefined();
const actAsync = async () => await caller.testConnection(input);
await expect(actAsync()).resolves.toBeUndefined();
},
);
@@ -395,8 +395,8 @@ describe("testConnection should test the connection to an integration", () => {
],
};
const act = async () => await caller.testConnection(input);
await expect(act()).resolves.toBeUndefined();
const actAsync = async () => await caller.testConnection(input);
await expect(actAsync()).resolves.toBeUndefined();
});
it("should be successful when overriding one of the secrets for an existing nzbGet integration", async () => {
@@ -439,8 +439,8 @@ describe("testConnection should test the connection to an integration", () => {
],
};
const act = async () => await caller.testConnection(input);
await expect(act()).resolves.toBeUndefined();
const actAsync = async () => await caller.testConnection(input);
await expect(actAsync()).resolves.toBeUndefined();
});
it("should fail when a required secret is missing for an existing nzbGet integration", async () => {
@@ -477,8 +477,8 @@ describe("testConnection should test the connection to an integration", () => {
],
};
const act = async () => await caller.testConnection(input);
await expect(act()).rejects.toThrow("SECRETS_NOT_DEFINED");
const actAsync = async () => await caller.testConnection(input);
await expect(actAsync()).rejects.toThrow("SECRETS_NOT_DEFINED");
});
it("should fail when the updating integration does not exist", async () => {
@@ -488,7 +488,7 @@ describe("testConnection should test the connection to an integration", () => {
session: null,
});
const act = async () =>
const actAsync = async () =>
await caller.testConnection({
id: createId(),
kind: "nzbGet",
@@ -498,6 +498,6 @@ describe("testConnection should test the connection to an integration", () => {
{ kind: "password", value: "Password123!" },
],
});
await expect(act()).rejects.toThrow("SECRETS_NOT_DEFINED");
await expect(actAsync()).rejects.toThrow("SECRETS_NOT_DEFINED");
});
});

View File

@@ -183,9 +183,9 @@ describe("delete should remove invite by id", () => {
});
// Act
const act = async () => await caller.deleteInvite({ id: createId() });
const actAsync = async () => await caller.deleteInvite({ id: createId() });
// Assert
await expect(act()).rejects.toThrow("not found");
await expect(actAsync()).rejects.toThrow("not found");
});
});

View File

@@ -27,14 +27,14 @@ describe("initUser should initialize the first user", () => {
password: "test",
});
const act = async () =>
const actAsync = async () =>
await caller.initUser({
username: "test",
password: "12345678",
confirmPassword: "12345678",
});
await expect(act()).rejects.toThrow("User already exists");
await expect(actAsync()).rejects.toThrow("User already exists");
});
it("should create a user if none exists", async () => {
@@ -66,14 +66,14 @@ describe("initUser should initialize the first user", () => {
session: null,
});
const act = async () =>
const actAsync = async () =>
await caller.initUser({
username: "test",
password: "12345678",
confirmPassword: "12345679",
});
await expect(act()).rejects.toThrow("Passwords do not match");
await expect(actAsync()).rejects.toThrow("Passwords do not match");
});
it("should not create a user if the password is too short", async () => {
@@ -83,14 +83,14 @@ describe("initUser should initialize the first user", () => {
session: null,
});
const act = async () =>
const actAsync = async () =>
await caller.initUser({
username: "test",
password: "1234567",
confirmPassword: "1234567",
});
await expect(act()).rejects.toThrow("too_small");
await expect(actAsync()).rejects.toThrow("too_small");
});
});
@@ -175,7 +175,7 @@ describe("register should create a user with valid invitation", () => {
});
// Act
const act = async () =>
const actAsync = async () =>
await caller.register({
inviteId,
token: inviteToken,
@@ -186,7 +186,7 @@ describe("register should create a user with valid invitation", () => {
});
// Assert
await expect(act()).rejects.toThrow("Invalid invite");
await expect(actAsync()).rejects.toThrow("Invalid invite");
},
);
});