Skip to content

Commit

Permalink
✨ feat(deepsource): fix async issues
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed Nov 30, 2024
1 parent 14f6cb6 commit ec8e8de
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
// stories: ['../**/*.stories.@(ts|tsx|js|jsx)'],
addons: ["@storybook/addon-links", "@storybook/addon-essentials"],
// https://storybook.js.org/docs/react/configure/typescript#mainjs-configuration,
webpackFinal: async (config, { configType }) => {
webpackFinal: async (config) => {
const assetRule = config.module.rules.find(({ test }) => test.test(".svg"));
// exclude svg from the default storybook file-loader
assetRule.exclude = /\.svg$/;
Expand Down
4 changes: 1 addition & 3 deletions scripts/ci/check-file-segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ for (const fileName of files) {
}

if (errors.length > 0) {
console.error(`${errors.length} files not placed in the correct folders`);

console.error(errors.join(","));

process.exit(1);
throw new Error(`${errors.length} files not placed in the correct folders`);
}
2 changes: 1 addition & 1 deletion src/__tests__/_/api/setups/_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const setupAllTestData = async (domains: DomainTypes[]) => {
...portalTestData,
];

createCacheService().purge();
await createCacheService().purge();

await Promise.all(
allTestData
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/account/password.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ describe("pages/account/password", () => {
"New Password"
);

await closeAllToasts();

await userEvent.click(
screen.getByRole("button", { name: "Update Password" })
);
Expand Down
8 changes: 5 additions & 3 deletions src/__tests__/admin/settings/data.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ describe("pages/admin/settings/data", () => {
expect(await getToastMessage()).toBe(
"Metadata Columns Saved Successfully"
);

await closeAllToasts();
});

it("should display updated date values", async () => {
it("should display updated metatacolumns values", async () => {
render(
<TestProviders>
<GeneralDataSettings />
Expand Down Expand Up @@ -86,6 +84,8 @@ describe("pages/admin/settings/data", () => {
</TestProviders>
);

await closeAllToasts();

await userEvent.clear(screen.getByLabelText("Format"));

await userEvent.type(screen.getByLabelText("Format"), "yyyy MMM do");
Expand Down Expand Up @@ -127,6 +127,8 @@ describe("pages/admin/settings/data", () => {
expect(await getToastMessage()).toBe(
`Invalid Date FormatPlease go to https://date-fns.org/docs/format to see valid formats`
);

await closeAllToasts();
});

it("should show date format", async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/api/integrations/storage/active.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("/api/integrations/actions/[key]/index", () => {
const currentStorageKeyValueStoreApiService =
createKeyValueDomainPersistenceService<string>("current-storage");

currentStorageKeyValueStoreApiService.clearItem();
await currentStorageKeyValueStoreApiService.clearItem();

await setupAllTestData(["users", "credentials"]);
});
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/api/integrations/storage/credentials.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("/api/integrations/storage/[key]/credentials", () => {
const currentStorageKeyValueStoreApiService =
createKeyValueDomainPersistenceService<string>("current-storage");

currentStorageKeyValueStoreApiService.persistItem("s3");
await currentStorageKeyValueStoreApiService.persistItem("s3");

await setupAllTestData(["users"]);
await setupCredentialsTestData({
Expand Down
54 changes: 54 additions & 0 deletions src/__tests__/api/integrations/storage/list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,60 @@ describe("/api/integrations/storage/list", () => {
"key": "s3",
"title": "AWS S3",
},
{
"configurationSchema": {
"accessKey": {
"label": {
"id": "5k6ZTK",
"message": "Access Key",
},
"type": "text",
"validations": [
{
"validationType": "required",
},
],
},
"endpoint": {
"label": {
"id": "FCKppt",
"message": "Endpoint",
},
"type": "text",
"validations": [
{
"validationType": "required",
},
],
},
"port": {
"label": {
"id": "hZ6znB",
"message": "Port",
},
"type": "text",
"validations": [
{
"validationType": "required",
},
],
},
"secretKey": {
"label": {
"id": "E7bgrN",
"message": "Secret Key",
},
"type": "text",
"validations": [
{
"validationType": "required",
},
],
},
},
"key": "minio",
"title": "Minio",
},
{
"configurationSchema": {
"apiKey": {
Expand Down
37 changes: 30 additions & 7 deletions src/__tests__/integrations/variables__credentials.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable prettier/prettier */

import { render, screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import userEvent, {
PointerEventsCheckLevel,
} from "@testing-library/user-event";

import { AuthActions } from "@/frontend/hooks/auth/auth.actions";
import ManageVariables from "@/pages/admin/settings/variables";
Expand Down Expand Up @@ -301,18 +303,32 @@ describe("pages/integrations/variables => credentials", () => {
)
);

const dialog = await screen.findByRole("dialog");
const dialog = await screen.findByRole(
"dialog",
{},
{
timeout: 10000,
}
);

expect(within(dialog).getByText("Create Secret")).toBeInTheDocument();

await userEvent.type(within(dialog).getByLabelText("Key"), "NEW_SECRET");
await userEvent.type(within(dialog).getByLabelText("Key"), "NEW_SECRET", {
pointerEventsCheck: PointerEventsCheckLevel.Never,
});
await userEvent.type(
within(dialog).getByLabelText("Value"),
"new secret"
"new secret",
{
pointerEventsCheck: PointerEventsCheckLevel.Never,
}
);

await userEvent.click(
within(dialog).getByRole("button", { name: "Create Secret" })
within(dialog).getByRole("button", { name: "Create Secret" }),
{
pointerEventsCheck: PointerEventsCheckLevel.Never,
}
);

expect(await getToastMessage()).toBe("Secret Saved Successfully");
Expand Down Expand Up @@ -376,10 +392,17 @@ describe("pages/integrations/variables => credentials", () => {

expect(within(dialog).getByLabelText("Key")).toBeDisabled();

await userEvent.type(within(dialog).getByLabelText("Value"), "__updated");
await userEvent.type(
within(dialog).getByLabelText("Value"),
"__updated",
{
pointerEventsCheck: PointerEventsCheckLevel.Never,
}
);

await userEvent.click(
within(dialog).getByRole("button", { name: "Update Secret" })
within(dialog).getByRole("button", { name: "Update Secret" }),
{ pointerEventsCheck: PointerEventsCheckLevel.Never }
);

expect(await getToastMessage()).toBe("Secret Saved Successfully");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const handler = requestHandler({
});

describe("Request Validations => authenticatedUserValidationImpl", () => {
beforeAll(() => {
setupAllTestData(["users"]);
beforeAll(async () => {
await setupAllTestData(["users"]);
});

it("should return authenticated user", async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/backend/lib/temp-storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class TempStorageApiService {
return null;
}
if (isBefore(new Date(data.expiryDate), new Date())) {
this.clearItem(key);
await this.clearItem(key);
return null;
}
return JSON.parse(data.data) as T;
Expand Down
22 changes: 19 additions & 3 deletions src/frontend/components/app/table/filters/__tests__/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ describe("Table Filters", () => {
});
});

await user.selectOptions(screen.getByRole("combobox"), "Equal");
await user.click(screen.getByRole("combobox"));

await user.click(screen.getByRole("option", { name: "Equal" }));

await waitFor(() => {
expect(setFilterValueJestFn).toHaveBeenLastCalledWith({
Expand Down Expand Up @@ -254,6 +256,8 @@ describe("Table Filters", () => {
screen.getByRole("button", { name: "Filter Test Column By Id" })
);

await user.click(screen.getByRole("combobox"));

expect(
screen
.getAllByRole("option", { hidden: true })
Expand All @@ -272,7 +276,13 @@ describe("Table Filters", () => {
screen.getByRole("button", { name: "Filter Test Column By Id" })
);

await userEvent.type(screen.getByPlaceholderText("Enter value"), "12345");
await userEvent.type(
screen.getByPlaceholderText("Enter value"),
"12345",
{
pointerEventsCheck: PointerEventsCheckLevel.Never,
}
);

await waitFor(() => {
expect(setFilterValueJestFn).toHaveBeenLastCalledWith({
Expand Down Expand Up @@ -305,7 +315,9 @@ describe("Table Filters", () => {

expect(screen.getByPlaceholderText("Enter value")).toHaveValue("789");

await userEvent.type(screen.getByPlaceholderText("Enter value"), "0");
await userEvent.type(screen.getByPlaceholderText("Enter value"), "0", {
pointerEventsCheck: PointerEventsCheckLevel.Never,
});

await waitFor(() => {
expect(setFilterValueJestFn).toHaveBeenLastCalledWith({
Expand Down Expand Up @@ -338,6 +350,8 @@ describe("Table Filters", () => {
screen.getByRole("button", { name: "Filter Test Column By Boolean" })
);

await user.click(screen.getByRole("combobox"));

expect(screen.getAllByRole("option").map((option) => option.textContent))
.toMatchInlineSnapshot(`
[
Expand Down Expand Up @@ -456,6 +470,8 @@ describe("Table Filters", () => {
screen.getByRole("button", { name: "Filter Test Column By Status" })
);

await user.click(screen.getAllByRole("combobox")[0]);

expect(screen.getAllByRole("option").map((option) => option.textContent))
.toMatchInlineSnapshot(`
[
Expand Down
File renamed without changes.
54 changes: 54 additions & 0 deletions src/frontend/views/errors/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { render, screen } from "@testing-library/react";

import { USE_ROUTER_PARAMS } from "@/tests/constants";
import { TestProviders } from "@/tests/Provider";

import { NotFound } from "./NotFound";
import { ServerError } from "./ServerError";
import { UnAuthorized } from "./UnAuthorized";

describe("Error pages", () => {
beforeAll(() => {
const useRouter = jest.spyOn(require("next/router"), "useRouter");
useRouter.mockImplementation(USE_ROUTER_PARAMS({}));
});

it("renders the 500 error page", () => {
render(
<TestProviders>
<ServerError />
</TestProviders>
);

expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent("500");
expect(screen.getByRole("heading", { level: 3 })).toHaveTextContent(
"Internal Server Error"
);
});

it("renders the 403 error page", () => {
render(
<TestProviders>
<UnAuthorized />
</TestProviders>
);

expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent("403");
expect(screen.getByRole("heading", { level: 3 })).toHaveTextContent(
"Unauthorized"
);
});

it("renders the 404 error page", () => {
render(
<TestProviders>
<NotFound />
</TestProviders>
);

expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent("404");
expect(screen.getByRole("heading", { level: 3 })).toHaveTextContent(
"Page Not Found"
);
});
});
4 changes: 2 additions & 2 deletions src/frontend/views/settings/Entities/Selection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export function EntitiesSelection({
? {
orderList: sort.order,
key: "name",
on: (newOrder) => {
sort.save(newOrder);
on: async (newOrder) => {
await sort.save(newOrder);
},
}
: undefined
Expand Down

0 comments on commit ec8e8de

Please sign in to comment.