view data tests
This commit is contained in:
116
core/eslint-rules/domain-no-application.test.js
Normal file
116
core/eslint-rules/domain-no-application.test.js
Normal file
@@ -0,0 +1,116 @@
|
||||
const { RuleTester } = require('eslint');
|
||||
const rule = require('./domain-no-application');
|
||||
|
||||
const ruleTester = new RuleTester({
|
||||
parser: require.resolve('@typescript-eslint/parser'),
|
||||
parserOptions: {
|
||||
ecmaVersion: 2020,
|
||||
sourceType: 'module',
|
||||
ecmaFeatures: {
|
||||
jsx: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
ruleTester.run('domain-no-application', rule, {
|
||||
valid: [
|
||||
// Domain file importing from domain
|
||||
{
|
||||
filename: '/path/to/core/domain/user/User.ts',
|
||||
code: "import { UserId } from './UserId';",
|
||||
},
|
||||
// Domain file importing from shared
|
||||
{
|
||||
filename: '/path/to/core/domain/user/User.ts',
|
||||
code: "import { ValueObject } from '../shared/ValueObject';",
|
||||
},
|
||||
// Domain file importing from ports
|
||||
{
|
||||
filename: '/path/to/core/domain/user/User.ts',
|
||||
code: "import { UserRepository } from '../ports/UserRepository';",
|
||||
},
|
||||
// Non-domain file importing from application
|
||||
{
|
||||
filename: '/path/to/core/application/user/CreateUser.ts',
|
||||
code: "import { CreateUserCommand } from './CreateUserCommand';",
|
||||
},
|
||||
// Non-domain file importing from application
|
||||
{
|
||||
filename: '/path/to/core/application/user/CreateUser.ts',
|
||||
code: "import { UserService } from '../services/UserService';",
|
||||
},
|
||||
// Domain file with no imports
|
||||
{
|
||||
filename: '/path/to/core/domain/user/User.ts',
|
||||
code: "export class User {}",
|
||||
},
|
||||
// Domain file with multiple imports, none from application
|
||||
{
|
||||
filename: '/path/to/core/domain/user/User.ts',
|
||||
code: `
|
||||
import { UserId } from './UserId';
|
||||
import { UserName } from './UserName';
|
||||
import { ValueObject } from '../shared/ValueObject';
|
||||
`,
|
||||
},
|
||||
],
|
||||
|
||||
invalid: [
|
||||
// Domain file importing from application
|
||||
{
|
||||
filename: '/path/to/core/domain/user/User.ts',
|
||||
code: "import { CreateUserCommand } from '../application/user/CreateUserCommand';",
|
||||
errors: [
|
||||
{
|
||||
messageId: 'forbiddenImport',
|
||||
data: {
|
||||
source: '../application/user/CreateUserCommand',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
// Domain file importing from application with different path
|
||||
{
|
||||
filename: '/path/to/core/domain/user/User.ts',
|
||||
code: "import { UserService } from '../../application/services/UserService';",
|
||||
errors: [
|
||||
{
|
||||
messageId: 'forbiddenImport',
|
||||
data: {
|
||||
source: '../../application/services/UserService',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
// Domain file importing from application with absolute path
|
||||
{
|
||||
filename: '/path/to/core/domain/user/User.ts',
|
||||
code: "import { CreateUserCommand } from 'core/application/user/CreateUserCommand';",
|
||||
errors: [
|
||||
{
|
||||
messageId: 'forbiddenImport',
|
||||
data: {
|
||||
source: 'core/application/user/CreateUserCommand',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
// Domain file with multiple imports, one from application
|
||||
{
|
||||
filename: '/path/to/core/domain/user/User.ts',
|
||||
code: `
|
||||
import { UserId } from './UserId';
|
||||
import { CreateUserCommand } from '../application/user/CreateUserCommand';
|
||||
import { UserName } from './UserName';
|
||||
`,
|
||||
errors: [
|
||||
{
|
||||
messageId: 'forbiddenImport',
|
||||
data: {
|
||||
source: '../application/user/CreateUserCommand',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
Reference in New Issue
Block a user