Skip to content

Commit

Permalink
test: add validateConfig tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrrt committed Dec 14, 2023
1 parent fd641a0 commit 1830f88
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 52 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@types/jest": "^29.5.8",
"@types/node": "^20.9.0",
"eslint": "^8.48.0",
"jest": "^29.7.0",
"prettier": "^3.0.3",
"ts-jest": "^29.1.1",
"tsup": "^7.2.0",
Expand All @@ -25,7 +26,6 @@
"graphql": "^16.8.1",
"graphql-yoga": "^5.0.0",
"itty-durable": "^2.1.0",
"jest": "^29.7.0",
"node-fetch": "2.7.0",
"react-icons": "^4.12.0"
}
Expand Down
37 changes: 10 additions & 27 deletions packages/cli/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
module.exports = {
moduleFileExtensions: [
'js',
'ts',
'tsx',
],
// setupFilesAfterEnv: ['./jest.setup.js'],
transform: {
'^.+\\.(ts|tsx)?$': [
'ts-jest'
],
},
modulePaths: [
"<rootDir>",
],
moduleNameMapper: {
'^@authdog/(.*)$': '<rootDir>/packages/$1/src',
'^.+\\.tsx?$': ['ts-jest', {//the content you'd placed at "global"
babel: true,
tsconfig: 'tsconfig.json',
}]
},
testMatch: [
'**/**/*.test.(ts|js)',
'**/test/**/*.test.(ts|js)',
],
testPathIgnorePatterns: [
'/node_modules/',
'build',
],
testEnvironment: 'node',
rootDir: '.',
collectCoverageFrom: [
'!<rootDir>/src',
"transformIgnorePatterns": [
"/node_modules/",
],
preset: 'ts-jest',
// moduleNameMapper: {
// '^@authdog\/platform-utils$': require.resolve('@authdog/platform-utils'),
// }
}
3 changes: 2 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"start": "node .",
"dev": "tsc -w -p tsconfig.json",
"build": "tsc -p tsconfig.json"
"build": "tsc -p tsconfig.json",
"test": "jest"
},
"keywords": [],
"author": "",
Expand Down
37 changes: 17 additions & 20 deletions packages/cli/src/utils/validateConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global jest, describe, it, expect */
import { validateConfig } from './validateConfig'; // Update with the correct file path

describe('validateConfig function', () => {
Expand Down Expand Up @@ -33,30 +34,26 @@ describe('validateConfig function', () => {
},
],
jwksUri: 'invalid uri', // invalid URL format
};
};

it ("should return true", () => {
expect(true).toBe(true);
it('should validate a valid config object without throwing errors', () => {
expect(() => validateConfig(validConfig)).not.toThrow();
});

// it('should validate a valid config object without throwing errors', () => {
// expect(() => validateConfig(validConfig)).not.toThrow();
// });

// it('should throw a ZodError for an invalid config object', () => {
// expect(() => validateConfig(invalidConfig)).toThrow();
// });
it('should throw a ZodError for an invalid config object', () => {
expect(() => validateConfig(invalidConfig)).toThrow();
});

// it('should log validation errors to the console for an invalid config object', () => {
// const consoleErrorSpy = jest.spyOn(console, 'error');
// consoleErrorSpy.mockImplementation(() => {}); // Mock console.error to do nothing
it('should log validation errors to the console for an invalid config object', () => {
const consoleErrorSpy = jest.spyOn(console, 'error');
consoleErrorSpy.mockImplementation(() => {}); // Mock console.error to do nothing

// try {
// validateConfig(invalidConfig);
// } catch (error) {
// expect(consoleErrorSpy).toHaveBeenCalled();
// }
try {
validateConfig(invalidConfig);
} catch (error) {
expect(consoleErrorSpy).toHaveBeenCalled();
}

// consoleErrorSpy.mockRestore(); // Restore console.error
// });
consoleErrorSpy.mockRestore(); // Restore console.error
});
});
Loading

0 comments on commit 1830f88

Please sign in to comment.