Skip to content

Commit

Permalink
Merge pull request #174 from zhumeisongsong/feature/add-auth-domain
Browse files Browse the repository at this point in the history
feat: ✨ add @auth/domain
  • Loading branch information
zhumeisongsong authored Feb 2, 2025
2 parents 0ab6436 + 95f0438 commit f12c1a8
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libs/auth/domain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# auth-domain

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test auth-domain` to execute the unit tests via [Jest](https://jestjs.io).
3 changes: 3 additions & 0 deletions libs/auth/domain/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const baseConfig = require('../../../eslint.config.js');

module.exports = [...baseConfig];
10 changes: 10 additions & 0 deletions libs/auth/domain/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
displayName: 'auth-domain',
preset: '../../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../../coverage/libs/auth/domain',
};
9 changes: 9 additions & 0 deletions libs/auth/domain/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "auth-domain",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/auth/domain/src",
"projectType": "library",
"tags": [],
"// targets": "to see all targets run: nx show project auth-domain --web",
"targets": {}
}
1 change: 1 addition & 0 deletions libs/auth/domain/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/auth-service.port';
34 changes: 34 additions & 0 deletions libs/auth/domain/src/lib/auth-service.port.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { AuthService } from './auth-service.port';

describe('AuthService', () => {
let service: AuthService;

beforeEach(() => {
service = {
signIn: jest.fn(),
};
});

describe('signIn', () => {
const email = '[email protected]';
const password = 'password123';

it('should call signIn with email and password', async () => {
await service.signIn(email, password);
expect(service.signIn).toHaveBeenCalledWith(email, password);
});

it('should return void when successful', async () => {
(service.signIn as jest.Mock).mockResolvedValue(undefined);
const result = await service.signIn(email, password);
expect(result).toBeUndefined();
});

it('should throw error when signIn fails', async () => {
const error = new Error('Auth failed');
(service.signIn as jest.Mock).mockRejectedValue(error);

await expect(service.signIn(email, password)).rejects.toThrow(error);
});
});
});
5 changes: 5 additions & 0 deletions libs/auth/domain/src/lib/auth-service.port.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface AuthService {
signIn(email: string, pass: string): Promise<void>;
}

export const AUTH_SERVICE = Symbol('AUTH_SERVICE');
23 changes: 23 additions & 0 deletions libs/auth/domain/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"importHelpers": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noPropertyAccessFromIndexSignature": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
10 changes: 10 additions & 0 deletions libs/auth/domain/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
}
15 changes: 15 additions & 0 deletions libs/auth/domain/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"module": "commonjs",
"moduleResolution": "node10",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"libs/applications/self-care-config/src/index.ts"
],
"@auth/application": ["libs/auth/application/src/index.ts"],
"@auth/domain": ["libs/auth/domain/src/index.ts"],
"@auth/interface-adapters": ["libs/auth/interface-adapters/src/index.ts"],
"@self-care-tasks/application": [
"libs/self-care-tasks/application/src/index.ts"
Expand Down

0 comments on commit f12c1a8

Please sign in to comment.