diff --git a/jest.config.js b/jest.config.js index de855f3..033904e 100644 --- a/jest.config.js +++ b/jest.config.js @@ -14,7 +14,7 @@ module.exports = { }, globals: { 'ts-jest': { - diagnostics: false, + diagnostics: true, tsconfig: './tsconfig.json', }, }, diff --git a/lib/generateRoutes/index.test.ts b/lib/generateRoutes/index.test.ts index 9da2662..9452804 100644 --- a/lib/generateRoutes/index.test.ts +++ b/lib/generateRoutes/index.test.ts @@ -19,16 +19,17 @@ function deleteBuildFolder(): void { } } -function doTestImport(tsData: string): unknown { +function doTestImport(tsData: string): void { const filename = `${randomUUID()}.ts`; fs.writeFileSync(path.join(buildFolder, filename), tsData); - // eslint-disable-next-line max-len - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, security/detect-non-literal-require, import/no-dynamic-require, global-require, @typescript-eslint/no-var-requires - const endpoints = require(`../../build/tests/${filename}`); - expect(endpoints).toBeTruthy(); // Probably a better test here, but I don't know what it would be - return endpoints; + expect(() => { + // eslint-disable-next-line max-len + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, security/detect-non-literal-require, import/no-dynamic-require, global-require, @typescript-eslint/no-var-requires + const endpoints = require(`../../build/tests/${filename}`); + expect(endpoints).toBeTruthy(); // Probably a better test here, but I don't know what it would be + }).not.toThrow(); } describe('generateTypescript', () => { @@ -47,7 +48,7 @@ describe('generateTypescript', () => { const typeImport = await generateTypes(apiPath, path.join(buildFolder, `${randomUUID()}_types.ts`)); - const tsData = generateTypescript(api, typeImport).replace('apollo-rest-utils', '../../lib'); + const tsData = generateTypescript(api, typeImport).replace(/apollo-rest-utils/g, '../../lib'); expect(tsData).toBeTruthy(); // Not empty, null, or undefined @@ -70,8 +71,8 @@ describe('normalizeName', () => { describe('pathToType', () => { it.each([ ['/login', 'LoginResponse'], - ['/high-schools/search', 'SearchResponse'], - ['/invitations/{studentKey}/users/{mentorEmail}', 'UsersResponse'], + ['/high-schools/search', 'HighSchoolsSearchResponse'], + ['/invitations/{studentKey}/users/{mentorEmail}', 'InvitationsByStudentkeyUsersByMentoremailResponse'], ])('path %s produces type name %s', (pathName, expectedTypeName) => { expect(pathToType(pathName)).toEqual(expectedTypeName); }); diff --git a/lib/generateRoutes/index.ts b/lib/generateRoutes/index.ts index 6bc13e8..c551d64 100644 --- a/lib/generateRoutes/index.ts +++ b/lib/generateRoutes/index.ts @@ -54,7 +54,7 @@ export function normalizeName(name: string): string { } export function pathToType(endpointPath: string, isArray = false): string { - const result = `${_.camelCase(_.last(endpointPath.split('/').filter(x => !x.startsWith('{'))))}Response`; + const result = `${_.camelCase(normalizeName(endpointPath))}Response`; return `${isArray ? '[' : ''}${result.replace(result[0], result[0].toUpperCase())}${isArray ? ']' : ''}`; } diff --git a/lib/useRestQuery/index.test.ts b/lib/useRestQuery/index.test.ts index a8234b8..d9ff461 100644 --- a/lib/useRestQuery/index.test.ts +++ b/lib/useRestQuery/index.test.ts @@ -114,7 +114,7 @@ describe('useRestQuery Library', () => { const wrappedRestQuery = wrapRestClientQuery<'refreshToken'>(); const { data } = await wrappedRestQuery({ - client: clientMock as unknown as ApolloClient, + client: clientMock as unknown as ApolloClient, endpoint: dummyEndpoint, query: gql` query TestClientQuery($input: input) {