Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
danetsao committed Feb 21, 2024
1 parent d2b7cd1 commit 6e0babb
Show file tree
Hide file tree
Showing 25 changed files with 150 additions and 216 deletions.
10 changes: 4 additions & 6 deletions src/api/dto/from/dtoToCriteria.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ describe('DTO to criteria conversion for initial values', () => {
feeFineOwnerId: 'owner-id',
},
],
])('converts fee type %s with known types %s to %s', (input, feeFineTypes, expected) =>
expect(dtoToCriteria(input, feeFineTypes, [], { currency: 'USD' } as StripesType, intlEn)).toEqual(expected),
);
])('converts fee type %s with known types %s to %s', (input, feeFineTypes, expected) => expect(dtoToCriteria(input, feeFineTypes, [], { currency: 'USD' } as StripesType, intlEn)).toEqual(expected));

it.each<[BursarExportFilterLocation, LocationDTO[], CriteriaTerminal]>([
[
Expand Down Expand Up @@ -204,9 +202,9 @@ describe('DTO to criteria conversion for initial values', () => {
locationId: 'location-id',
},
],
])('converts location %s with known locations %s to %s', (input, locations, expected) =>
expect(dtoToCriteria(input, [], locations, { currency: 'USD' } as StripesType, intlEn)).toEqual(expected),
);
])('converts location %s with known locations %s to %s', (input, locations, expected) => expect(
dtoToCriteria(input, [], locations, { currency: 'USD' } as StripesType, intlEn)
).toEqual(expected));

it('converts amount with EUR currency', () => {
const input: BursarExportFilterDTO = { type: 'Amount', condition: 'LESS_THAN', amount: 124 };
Expand Down
4 changes: 1 addition & 3 deletions src/api/dto/from/dtoToLengthControl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ test.each([
{ character: 'a', length: 3, direction: 'FRONT', truncate: false },
{ character: 'a', length: '3', direction: 'FRONT', truncate: false },
],
] as const)('Length control conversion from %s to %s', (input, expected) =>
expect(dtoToLengthControl(input)).toEqual(expected),
);
] as const)('Length control conversion from %s to %s', (input, expected) => expect(dtoToLengthControl(input)).toEqual(expected));
4 changes: 1 addition & 3 deletions src/api/dto/from/dtoToScheduling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,4 @@ test.each<[SchedulingDTO, FormValues['scheduling']]>([
],
},
],
])('Converts scheduling DTO %s to %s', (input, expected) =>
expect(dtoToScheduling(input, LOCALE_WEEKDAYS)).toEqual(expected),
);
])('Converts scheduling DTO %s to %s', (input, expected) => expect(dtoToScheduling(input, LOCALE_WEEKDAYS)).toEqual(expected));
6 changes: 3 additions & 3 deletions src/api/dto/from/dtoToTransfer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('dtoToTransfer', () => {
},
},
],
])('Converts transfer DTO %s with known accounts %s to %s', (input, transferAccounts, expected) =>
expect(dtoToTransfer(input, [], [], transferAccounts, { currency: 'USD' } as StripesType, intlEn)).toEqual(expected),
);
])('Converts transfer DTO %s with known accounts %s to %s', (input, transferAccounts, expected) => expect(dtoToTransfer(
input, [], [], transferAccounts, { currency: 'USD' } as StripesType, intlEn
)).toEqual(expected));
});
2 changes: 1 addition & 1 deletion src/api/dto/to/dataToDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function dataTokenToDto(token: DataToken): BursarExportDataTokenDTO {
}

export function userDataToDto(token: DataToken & { type: DataTokenType.USER_DATA }): BursarExportDataTokenDTO {
if (token.userAttribute == 'FOLIO_ID') {
if (token.userAttribute === 'FOLIO_ID') {
return {
type: 'UserData',
value: token.userAttribute,
Expand Down
34 changes: 16 additions & 18 deletions src/api/dto/to/formValuesToDto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,21 @@ describe('Form values conversion', () => {
},
};

it('converts non-aggregate values', () =>
expect(formValuesToDto({ ...TEST_VALUE, aggregate: false })).toEqual({
...EXPECTED,
groupByPatron: false,
data: [{ type: 'Constant', value: 'non-aggregate data' }],
}));
it('converts non-aggregate values', () => expect(formValuesToDto({ ...TEST_VALUE, aggregate: false })).toEqual({
...EXPECTED,
groupByPatron: false,
data: [{ type: 'Constant', value: 'non-aggregate data' }],
}));

it('converts aggregate values', () =>
expect(formValuesToDto({ ...TEST_VALUE, aggregate: true })).toEqual({
...EXPECTED,
groupByPatron: true,
groupByPatronFilter: {
type: 'Aggregate',
amount: 0,
condition: 'GREATER_THAN_EQUAL',
property: 'NUM_ROWS',
},
data: [{ type: 'Constant', value: 'aggregate data' }],
}));
it('converts aggregate values', () => expect(formValuesToDto({ ...TEST_VALUE, aggregate: true })).toEqual({
...EXPECTED,
groupByPatron: true,
groupByPatronFilter: {
type: 'Aggregate',
amount: 0,
condition: 'GREATER_THAN_EQUAL',
property: 'NUM_ROWS',
},
data: [{ type: 'Constant', value: 'aggregate data' }],
}));
});
85 changes: 37 additions & 48 deletions src/api/mutators/useAutomaticSchedulerMutation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ describe('Automatic scheduling mutation', () => {
});

const contextMock = jest.fn();
const wrapper = ({ children }: { children: ReactNode }) =>
withIntlConfiguration(
<QueryClientProvider client={new QueryClient()}>
<CalloutContext.Provider value={{ sendCallout: contextMock }}>{children}</CalloutContext.Provider>
</QueryClientProvider>,
);
const wrapper = ({ children }: { children: ReactNode }) => withIntlConfiguration(
<QueryClientProvider client={new QueryClient()}>
<CalloutContext.Provider value={{ sendCallout: contextMock }}>{children}</CalloutContext.Provider>
</QueryClientProvider>,
);

it('handles successful responses', async () => {
const { result: mutator } = renderHook(() => useAutomaticSchedulerMutation(), { wrapper });
Expand All @@ -45,22 +44,18 @@ describe('Automatic scheduling mutation', () => {
} as any);
});

await waitFor(() =>
expect(postMock).toHaveBeenLastCalledWith('data-export-spring/configs', {
json: {
type: 'BURSAR_FEES_FINES',
exportTypeSpecificParameters: { bursarFeeFines: 'bursar data' },
schedulingData: 'is here!',
},
}),
);

await waitFor(() =>
expect(contextMock).toHaveBeenLastCalledWith({
type: 'success',
message: 'Configuration saved',
}),
);
await waitFor(() => expect(postMock).toHaveBeenLastCalledWith('data-export-spring/configs', {
json: {
type: 'BURSAR_FEES_FINES',
exportTypeSpecificParameters: { bursarFeeFines: 'bursar data' },
schedulingData: 'is here!',
},
}));

await waitFor(() => expect(contextMock).toHaveBeenLastCalledWith({
type: 'success',
message: 'Configuration saved',
}));
});

it('handles error responses', async () => {
Expand All @@ -75,24 +70,20 @@ describe('Automatic scheduling mutation', () => {
} as any);
});

await waitFor(() =>
expect(postMock).toHaveBeenLastCalledWith('data-export-spring/configs', {
json: {
type: 'BURSAR_FEES_FINES',
exportTypeSpecificParameters: {
bursarFeeFines: 'bursar data that fails',
},
schedulingData: 'is here!',
await waitFor(() => expect(postMock).toHaveBeenLastCalledWith('data-export-spring/configs', {
json: {
type: 'BURSAR_FEES_FINES',
exportTypeSpecificParameters: {
bursarFeeFines: 'bursar data that fails',
},
}),
);

await waitFor(() =>
expect(contextMock).toHaveBeenLastCalledWith({
type: 'error',
message: 'Failed to save job',
}),
);
schedulingData: 'is here!',
},
}));

await waitFor(() => expect(contextMock).toHaveBeenLastCalledWith({
type: 'error',
message: 'Failed to save job',
}));
});

it('calls post when no initial config is available', async () => {
Expand Down Expand Up @@ -144,15 +135,13 @@ describe('Automatic scheduling mutation', () => {
} as any);
});

waitFor(async () =>
expect(putMock).toHaveBeenCalledWith('data-export-spring/configs/foo', {
json: {
id: 'foo',
exportTypeSpecificParameters: { bursarFeeFines: 'bursar data' },
schedulingData: 'is here!',
},
}),
);
waitFor(async () => expect(putMock).toHaveBeenCalledWith('data-export-spring/configs/foo', {
json: {
id: 'foo',
exportTypeSpecificParameters: { bursarFeeFines: 'bursar data' },
schedulingData: 'is here!',
},
}));
expect(postMock).not.toHaveBeenCalled();

// check invalidation
Expand Down
61 changes: 26 additions & 35 deletions src/api/mutators/useManualSchedulerMutation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ jest.mock('@folio/stripes/core', () => ({

describe('Automatic scheduling mutation', () => {
const contextMock = jest.fn();
const wrapper = ({ children }: { children: ReactNode }) =>
withIntlConfiguration(
<QueryClientProvider client={new QueryClient()}>
<CalloutContext.Provider value={{ sendCallout: contextMock }}>{children}</CalloutContext.Provider>
</QueryClientProvider>,
);
const wrapper = ({ children }: { children: ReactNode }) => withIntlConfiguration(
<QueryClientProvider client={new QueryClient()}>
<CalloutContext.Provider value={{ sendCallout: contextMock }}>{children}</CalloutContext.Provider>
</QueryClientProvider>,
);

it('handles successful responses', async () => {
const { result: mutator } = renderHook(() => useManualSchedulerMutation(), {
Expand All @@ -34,21 +33,17 @@ describe('Automatic scheduling mutation', () => {
mutator.current('bursar data' as any);
});

await waitFor(() =>
expect(kyMock).toHaveBeenLastCalledWith('data-export-spring/jobs', {
json: {
type: 'BURSAR_FEES_FINES',
exportTypeSpecificParameters: { bursarFeeFines: 'bursar data' },
},
}),
);
await waitFor(() => expect(kyMock).toHaveBeenLastCalledWith('data-export-spring/jobs', {
json: {
type: 'BURSAR_FEES_FINES',
exportTypeSpecificParameters: { bursarFeeFines: 'bursar data' },
},
}));

await waitFor(() =>
expect(contextMock).toHaveBeenLastCalledWith({
type: 'success',
message: 'Job has been scheduled',
}),
);
await waitFor(() => expect(contextMock).toHaveBeenLastCalledWith({
type: 'success',
message: 'Job has been scheduled',
}));
});

it('handles error responses', async () => {
Expand All @@ -62,22 +57,18 @@ describe('Automatic scheduling mutation', () => {
mutator.current('bursar data that fails' as any);
});

await waitFor(() =>
expect(kyMock).toHaveBeenLastCalledWith('data-export-spring/jobs', {
json: {
type: 'BURSAR_FEES_FINES',
exportTypeSpecificParameters: {
bursarFeeFines: 'bursar data that fails',
},
await waitFor(() => expect(kyMock).toHaveBeenLastCalledWith('data-export-spring/jobs', {
json: {
type: 'BURSAR_FEES_FINES',
exportTypeSpecificParameters: {
bursarFeeFines: 'bursar data that fails',
},
}),
);
},
}));

await waitFor(() =>
expect(contextMock).toHaveBeenLastCalledWith({
type: 'error',
message: 'Failed to start job',
}),
);
await waitFor(() => expect(contextMock).toHaveBeenLastCalledWith({
type: 'error',
message: 'Failed to start job',
}));
});
});
35 changes: 16 additions & 19 deletions src/api/mutators/useManualSchedulerMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,25 @@ export default function useManualSchedulerMutation() {
const intl = useIntl();

const mutation = useMutation(
async (parameters: BursarExportJobDTO) =>
ky.post('data-export-spring/jobs', {
json: {
type: 'BURSAR_FEES_FINES',
exportTypeSpecificParameters: { bursarFeeFines: parameters },
},
}),
async (parameters: BursarExportJobDTO) => ky.post('data-export-spring/jobs', {
json: {
type: 'BURSAR_FEES_FINES',
exportTypeSpecificParameters: { bursarFeeFines: parameters },
},
}),
{
onError: () =>
context.sendCallout({
type: 'error',
message: intl.formatMessage({
id: 'ui-plugin-bursar-export.bursarExports.scheduler.mutation.manual.error',
}),
onError: () => context.sendCallout({
type: 'error',
message: intl.formatMessage({
id: 'ui-plugin-bursar-export.bursarExports.scheduler.mutation.manual.error',
}),
onSuccess: () =>
context.sendCallout({
type: 'success',
message: intl.formatMessage({
id: 'ui-plugin-bursar-export.bursarExports.scheduler.mutation.manual.success',
}),
}),
onSuccess: () => context.sendCallout({
type: 'success',
message: intl.formatMessage({
id: 'ui-plugin-bursar-export.bursarExports.scheduler.mutation.manual.success',
}),
}),
},
);

Expand Down
3 changes: 1 addition & 2 deletions src/api/queries/useCampuses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export default function useCampuses() {

return useQuery<CampusDTO[]>(
['ui-plugin-bursar-export', 'campuses'],
async () =>
(await ky.get(`location-units/campuses?cql.allRecords=1&limit=${MAX_LIMIT}`).json<CampusesResponse>()).loccamps,
async () => (await ky.get(`location-units/campuses?cql.allRecords=1&limit=${MAX_LIMIT}`).json<CampusesResponse>()).loccamps,
);
}
15 changes: 7 additions & 8 deletions src/api/queries/useCurrentConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ export default function useCurrentConfig() {

return useQuery<SavedJobConfiguration | null>(
['ui-plugin-bursar-export', 'current-config'],
async () =>
(
await ky
.get('data-export-spring/configs', {
searchParams: { limit: 1, query: 'type==BURSAR_FEES_FINES' },
})
.json<CurrentConfigResponse>()
).configs?.[0] ?? null,
async () => (
await ky
.get('data-export-spring/configs', {
searchParams: { limit: 1, query: 'type==BURSAR_FEES_FINES' },
})
.json<CurrentConfigResponse>()
).configs?.[0] ?? null,
);
}
5 changes: 2 additions & 3 deletions src/api/queries/useInstitutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ export default function useInstitutions() {

return useQuery<InstitutionDTO[]>(
['ui-plugin-bursar-export', 'institutions'],
async () =>
(await ky.get(`location-units/institutions?cql.allRecords=1&limit=${MAX_LIMIT}`).json<InstitutionsResponse>())
.locinsts,
async () => (await ky.get(`location-units/institutions?cql.allRecords=1&limit=${MAX_LIMIT}`).json<InstitutionsResponse>())
.locinsts,
);
}
3 changes: 1 addition & 2 deletions src/api/queries/useLibraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export default function useLibraries() {

return useQuery<LibraryDTO[]>(
['ui-plugin-bursar-export', 'libraries'],
async () =>
(await ky.get(`location-units/libraries?cql.allRecords=1&limit=${MAX_LIMIT}`).json<LibrariesResponse>()).loclibs,
async () => (await ky.get(`location-units/libraries?cql.allRecords=1&limit=${MAX_LIMIT}`).json<LibrariesResponse>()).loclibs,
);
}
Loading

0 comments on commit 6e0babb

Please sign in to comment.