Skip to content

Commit

Permalink
🪟 🐛 Schedule type cron bug fix (airbytehq#17058)
Browse files Browse the repository at this point in the history
* remove inaccurate and unneeded setting of schedule type

* Fixing & adding tests

Co-authored-by: KC <krishna@airbyte.io>
  • Loading branch information
2 people authored and robbinhan committed Sep 29, 2022
1 parent 949e61e commit 61873e2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import mockDest from "test-utils/mock-data/mockDestinationDefinition.json";
import mockWorkspace from "test-utils/mock-data/mockWorkspace.json";
import { TestWrapper } from "test-utils/testutils";

import { WebBackendConnectionRead } from "core/request/AirbyteClient";
import { ConnectionScheduleType, WebBackendConnectionRead } from "core/request/AirbyteClient";

import { ModalCancel } from "../Modal";
import {
Expand Down Expand Up @@ -74,7 +74,12 @@ describe("ConnectionFormService", () => {
expect(resetForm).toBeCalledWith({ values: testValues });
expect(onSubmit).toBeCalledWith({
operations: [],
scheduleType: "manual",
scheduleData: {
cron: {
cronExpression: undefined,
cronTimeZone: undefined,
},
},
syncCatalog: {
streams: undefined,
},
Expand All @@ -83,6 +88,59 @@ describe("ConnectionFormService", () => {
expect(result.current.errorMessage).toBe(null);
});

const expectation = {
[ConnectionScheduleType.basic]: {
basicSchedule: {
timeUnit: undefined,
units: undefined,
},
},
[ConnectionScheduleType.manual]: undefined,
[ConnectionScheduleType.cron]: {
cron: {
cronExpression: undefined,
cronTimeZone: undefined,
},
},
};

Object.values(ConnectionScheduleType).forEach((scheduleType) => {
it(`should return expected results when onSubmit is called with ${scheduleType}`, async () => {
const { result } = renderHook(useConnectionFormService, {
wrapper: Wrapper,
initialProps: {
connection: mockConnection as WebBackendConnectionRead,
mode: "create",
formId: Math.random().toString(),
onSubmit,
onAfterSubmit,
onCancel,
formDirty: false,
},
});

const resetForm = jest.fn();
const testValues: any = {
scheduleType,
};
await act(async () => {
await result.current.onFormSubmit(testValues, { resetForm } as any);
});

expect(resetForm).toBeCalledWith({ values: testValues });
expect(onSubmit).toBeCalledWith({
operations: [],
scheduleData: expectation[scheduleType],
scheduleType,
syncCatalog: {
streams: undefined,
},
});
expect(onAfterSubmit).toBeCalledWith();
expect(result.current.errorMessage).toBe(null);
});
});

it("should catch if onSubmit throws and generate an error message", async () => {
const errorMessage = "asdf";
onSubmit.mockImplementation(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ const useConnectionForm = ({

const onFormSubmit = useCallback(
async (values: FormikConnectionFormValues, formikHelpers: FormikHelpers<FormikConnectionFormValues>) => {
// Set the scheduleType based on the schedule value
values.scheduleType = values.scheduleData?.basicSchedule
? ConnectionScheduleType.basic
: ConnectionScheduleType.manual;

// TODO: We should align these types
// With the PATCH-style endpoint available we might be able to forego this pattern
const formValues: ConnectionFormValues = connectionValidationSchema.cast(values, {
Expand Down

0 comments on commit 61873e2

Please sign in to comment.