Skip to content

Commit 3d6ce82

Browse files
teallarsonkrishnaglick
authored andcommitted
🪟 🐛 Schedule type cron bug fix (airbytehq#17058)
* remove inaccurate and unneeded setting of schedule type * Fixing & adding tests Co-authored-by: KC <krishna@airbyte.io>
1 parent 8f287a2 commit 3d6ce82

File tree

2 files changed

+60
-7
lines changed

2 files changed

+60
-7
lines changed

airbyte-webapp/src/hooks/services/Connection/ConnectionFormService.test.tsx

+60-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import mockDest from "test-utils/mock-data/mockDestinationDefinition.json";
88
import mockWorkspace from "test-utils/mock-data/mockWorkspace.json";
99
import { TestWrapper } from "test-utils/testutils";
1010

11-
import { WebBackendConnectionRead } from "core/request/AirbyteClient";
11+
import { ConnectionScheduleType, WebBackendConnectionRead } from "core/request/AirbyteClient";
1212

1313
import { ModalCancel } from "../Modal";
1414
import {
@@ -74,7 +74,12 @@ describe("ConnectionFormService", () => {
7474
expect(resetForm).toBeCalledWith({ values: testValues });
7575
expect(onSubmit).toBeCalledWith({
7676
operations: [],
77-
scheduleType: "manual",
77+
scheduleData: {
78+
cron: {
79+
cronExpression: undefined,
80+
cronTimeZone: undefined,
81+
},
82+
},
7883
syncCatalog: {
7984
streams: undefined,
8085
},
@@ -83,6 +88,59 @@ describe("ConnectionFormService", () => {
8388
expect(result.current.errorMessage).toBe(null);
8489
});
8590

91+
const expectation = {
92+
[ConnectionScheduleType.basic]: {
93+
basicSchedule: {
94+
timeUnit: undefined,
95+
units: undefined,
96+
},
97+
},
98+
[ConnectionScheduleType.manual]: undefined,
99+
[ConnectionScheduleType.cron]: {
100+
cron: {
101+
cronExpression: undefined,
102+
cronTimeZone: undefined,
103+
},
104+
},
105+
};
106+
107+
Object.values(ConnectionScheduleType).forEach((scheduleType) => {
108+
it(`should return expected results when onSubmit is called with ${scheduleType}`, async () => {
109+
const { result } = renderHook(useConnectionFormService, {
110+
wrapper: Wrapper,
111+
initialProps: {
112+
connection: mockConnection as WebBackendConnectionRead,
113+
mode: "create",
114+
formId: Math.random().toString(),
115+
onSubmit,
116+
onAfterSubmit,
117+
onCancel,
118+
formDirty: false,
119+
},
120+
});
121+
122+
const resetForm = jest.fn();
123+
const testValues: any = {
124+
scheduleType,
125+
};
126+
await act(async () => {
127+
await result.current.onFormSubmit(testValues, { resetForm } as any);
128+
});
129+
130+
expect(resetForm).toBeCalledWith({ values: testValues });
131+
expect(onSubmit).toBeCalledWith({
132+
operations: [],
133+
scheduleData: expectation[scheduleType],
134+
scheduleType,
135+
syncCatalog: {
136+
streams: undefined,
137+
},
138+
});
139+
expect(onAfterSubmit).toBeCalledWith();
140+
expect(result.current.errorMessage).toBe(null);
141+
});
142+
});
143+
86144
it("should catch if onSubmit throws and generate an error message", async () => {
87145
const errorMessage = "asdf";
88146
onSubmit.mockImplementation(async () => {

airbyte-webapp/src/hooks/services/Connection/ConnectionFormService.tsx

-5
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ const useConnectionForm = ({
5353

5454
const onFormSubmit = useCallback(
5555
async (values: FormikConnectionFormValues, formikHelpers: FormikHelpers<FormikConnectionFormValues>) => {
56-
// Set the scheduleType based on the schedule value
57-
values.scheduleType = values.scheduleData?.basicSchedule
58-
? ConnectionScheduleType.basic
59-
: ConnectionScheduleType.manual;
60-
6156
// TODO: We should align these types
6257
// With the PATCH-style endpoint available we might be able to forego this pattern
6358
const formValues: ConnectionFormValues = connectionValidationSchema.cast(values, {

0 commit comments

Comments
 (0)