Skip to content
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

feat: cleanup connector after test #295

Merged
merged 4 commits into from
Oct 27, 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
Original file line number Diff line number Diff line change
@@ -1,97 +1,11 @@
import { test, expect } from "@playwright/test";
import axios from "axios";
import { expectToDeleteConnector } from "./common/connector";
import { expectToSelectReactSelectOption } from "./helper";

test.describe.serial("Sync destination", () => {
const destinationId = "destination-http";
const destinationType = "HTTP";

// If there has a destination-http connector, we need to delete it then proceed the test.
test.beforeAll(async () => {
try {
const { data } = await axios.get(
`${process.env.NEXT_PUBLIC_CONNECTOR_BACKEND_BASE_URL}/${process.env.NEXT_PUBLIC_API_VERSION}/destination-connectors?view=VIEW_FULL`
);

const targetDestination = (data.destination_connectors as any[]).find(
(e) => e.id === destinationId
);

if (targetDestination) {
await axios.delete(
`${process.env.NEXT_PUBLIC_CONNECTOR_BACKEND_BASE_URL}/${process.env.NEXT_PUBLIC_API_VERSION}/destination-connectors/${destinationId}`
);
}
return Promise.resolve(data.destination_connectors);
} catch (err) {
return Promise.reject(err);
}
});

test("should create sync http destination", async ({ page }) => {
await page.goto("/destinations/create");

// Should select destination type - HTTP
await expectToSelectReactSelectOption(
page.locator("#react-select-definition-input"),
page.locator("data-testid=definition-selected-option", {
hasText: destinationType,
})
);

// Should set up destination
const setupButton = page.locator("button", { hasText: "Set up" });
await Promise.all([page.waitForNavigation(), setupButton.click()]);
expect(page.url()).toEqual(
`${process.env.NEXT_PUBLIC_MAIN_URL}/destinations`
);
});

test("should have destination list and navigate to destination details page", async ({
page,
}) => {
await page.goto("/destinations");

// Should have model item in list
const destinationItemTitle = page.locator("h3", { hasText: destinationId });
await expect(destinationItemTitle).toHaveCount(1);

// Should navigate to destination details page
await Promise.all([
page.waitForNavigation(),
page.locator("h3", { hasText: destinationId }).click(),
]);
expect(page.url()).toEqual(
`${process.env.NEXT_PUBLIC_MAIN_URL}/destinations/${destinationId}`
);
});

test("should have proper destination details page", async ({ page }) => {
await page.goto(`/destinations/${destinationId}`);

// Should have correct title
const destinationTitle = page.locator("h2", { hasText: destinationId });
await expect(destinationTitle).toHaveCount(1);

// Should have correct destination type
const destinationTypeOption = page.locator(
"data-testid=definition-selected-option"
);
await expect(destinationTypeOption).toHaveText(destinationType);

// Should disable edit button
const editButton = page.locator("button", {
hasText: "Edit",
});
expect(await editButton.isDisabled()).toBeTruthy();
});

test("should have delete destination modal and correctly delete destination", async ({
page,
}) => {
await expectToDeleteConnector(page, "destination", destinationId);
});
test.use({
launchOptions: {
slowMo: 50,
},
});

test.describe.serial("Async destination", () => {
Expand Down
4 changes: 4 additions & 0 deletions integration-test/helper/global-setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { chromium, FullConfig } from "@playwright/test";
import { addRegisteredUser } from "../common/mgmt";

// We use this setup to store the cookie in playwright-state. In this way,
// Playwright can automatically pick up the cookie among every test and it
// won't be redirected to onboarding page due to lack of login cookie.

async function globalSetup(config: FullConfig) {
const browser = await chromium.launch();
const page = await browser.newPage();
Expand Down
41 changes: 41 additions & 0 deletions integration-test/helper/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BrowserContext, expect, Locator, Page } from "@playwright/test";
import axios from "axios";

export const delay = (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms));
Expand Down Expand Up @@ -35,3 +36,43 @@ export const expectToSelectReactSelectOption = async (
await selectElement.click();
}
};

export const cleanUpDestination = async (id: string): Promise<void> => {
try {
const { data } = await axios.get(
`${process.env.NEXT_PUBLIC_CONNECTOR_BACKEND_BASE_URL}/${process.env.NEXT_PUBLIC_API_VERSION}/destination-connectors?view=VIEW_FULL`
);

const targetDestination = (data.destination_connectors as any[]).find(
(e) => e.id === id
);

if (targetDestination) {
await axios.delete(
`${process.env.NEXT_PUBLIC_CONNECTOR_BACKEND_BASE_URL}/${process.env.NEXT_PUBLIC_API_VERSION}/destination-connectors/${id}`
);
}
} catch (err) {
return Promise.reject(err);
}
};

export const cleanUpSource = async (id: string): Promise<void> => {
try {
const { data } = await axios.get(
`${process.env.NEXT_PUBLIC_CONNECTOR_BACKEND_BASE_URL}/${process.env.NEXT_PUBLIC_API_VERSION}/source-connectors?view=VIEW_FULL`
);

const targetSource = (data.source_connectors as any[]).find(
(e) => e.id === id
);

if (targetSource) {
await axios.delete(
`${process.env.NEXT_PUBLIC_CONNECTOR_BACKEND_BASE_URL}/${process.env.NEXT_PUBLIC_API_VERSION}/source-connectors/${id}`
);
}
} catch (err) {
return Promise.reject(err);
}
};
16 changes: 11 additions & 5 deletions integration-test/pipeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import {
expectToDeletePipeline,
expectToUpdatePipelineDescription,
} from "./common/pipeline";
import { delay, expectToSelectReactSelectOption } from "./helper";
import {
cleanUpDestination,
cleanUpSource,
expectToSelectReactSelectOption,
} from "./helper";

test.use({
launchOptions: {
Expand All @@ -30,6 +34,10 @@ test.describe
await axios.post(
`${process.env.NEXT_PUBLIC_MODEL_BACKEND_BASE_URL}/${process.env.NEXT_PUBLIC_API_VERSION}/models/${modelId}/instances/${modelInstanceTag}/undeploy`
);

// We need to clean up destination and source too
await cleanUpDestination("destination-http");
await cleanUpSource("source-http");
} catch (err) {
return Promise.reject(err);
}
Expand Down Expand Up @@ -199,15 +207,13 @@ test.describe
const password = "scylla-password";
const address = "scylla-address";

test.afterEach(async () => {
await delay(500);
});

test.afterAll(async () => {
try {
await axios.post(
`${process.env.NEXT_PUBLIC_MODEL_BACKEND_BASE_URL}/${process.env.NEXT_PUBLIC_API_VERSION}/models/${modelId}/instances/${modelInstanceTag}/undeploy`
);
await cleanUpDestination("destination-http");
await cleanUpSource("source-http");
} catch (err) {
return Promise.reject(err);
}
Expand Down
22 changes: 7 additions & 15 deletions integration-test/source.spec.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
import { test, expect } from "@playwright/test";
import axios from "axios";
import { expectToSelectReactSelectOption } from "./helper";
import { cleanUpSource, expectToSelectReactSelectOption } from "./helper";

test.describe.serial("Sync source", () => {
const sourceId = "source-grpc";

// If there has a source-grpc connector, we need to delete it then proceed the test.
test.beforeAll(async () => {
try {
const { data } = await axios.get(
`${process.env.NEXT_PUBLIC_CONNECTOR_BACKEND_BASE_URL}/${process.env.NEXT_PUBLIC_API_VERSION}/source-connectors?view=VIEW_FULL`
);

const targetDestination = (data.source_connectors as any[]).find(
(e) => e.id === sourceId
);

if (targetDestination) {
await axios.delete(
`${process.env.NEXT_PUBLIC_CONNECTOR_BACKEND_BASE_URL}/${process.env.NEXT_PUBLIC_API_VERSION}/source-connectors/${sourceId}`
);
}
return Promise.resolve(data.destination_connectors);
await cleanUpSource(sourceId);
} catch (err) {
return Promise.reject(err);
}
});

// We need to clean up source after the test too.
test.afterAll(async () => {
await cleanUpSource(sourceId);
});

test("should create source", async ({ page }) => {
await page.goto("/sources/create", { waitUntil: "networkidle" });

Expand Down
83 changes: 83 additions & 0 deletions integration-test/sync-destination.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { test, expect } from "@playwright/test";
import { expectToDeleteConnector } from "./common/connector";
import { cleanUpDestination, expectToSelectReactSelectOption } from "./helper";

test.describe.serial("Sync destination", () => {
const destinationId = "destination-http";
const destinationType = "HTTP";

// If there has a destination-http connector, we need to delete it then proceed the test.
test.beforeAll(async () => {
await cleanUpDestination(destinationId);
});

// Delete used sync destination connector to avoid conflict or casuing other
// test to fall.
test.afterAll(async () => {
await cleanUpDestination(destinationId);
});

test("should create sync http destination", async ({ page }) => {
await page.goto("/destinations/create");

// Should select destination type - HTTP
await expectToSelectReactSelectOption(
page.locator("#react-select-definition-input"),
page.locator("data-testid=definition-selected-option", {
hasText: destinationType,
})
);

// Should set up destination
const setupButton = page.locator("button", { hasText: "Set up" });
await Promise.all([page.waitForNavigation(), setupButton.click()]);
expect(page.url()).toEqual(
`${process.env.NEXT_PUBLIC_MAIN_URL}/destinations`
);
});

test("should have destination list and navigate to destination details page", async ({
page,
}) => {
await page.goto("/destinations");

// Should have model item in list
const destinationItemTitle = page.locator("h3", { hasText: destinationId });
await expect(destinationItemTitle).toHaveCount(1);

// Should navigate to destination details page
await Promise.all([
page.waitForNavigation(),
page.locator("h3", { hasText: destinationId }).click(),
]);
expect(page.url()).toEqual(
`${process.env.NEXT_PUBLIC_MAIN_URL}/destinations/${destinationId}`
);
});

test("should have proper destination details page", async ({ page }) => {
await page.goto(`/destinations/${destinationId}`);

// Should have correct title
const destinationTitle = page.locator("h2", { hasText: destinationId });
await expect(destinationTitle).toHaveCount(1);

// Should have correct destination type
const destinationTypeOption = page.locator(
"data-testid=definition-selected-option"
);
await expect(destinationTypeOption).toHaveText(destinationType);

// Should disable edit button
const editButton = page.locator("button", {
hasText: "Edit",
});
expect(await editButton.isDisabled()).toBeTruthy();
});

test("should have delete destination modal and correctly delete destination", async ({
page,
}) => {
await expectToDeleteConnector(page, "destination", destinationId);
});
});