nodejs-structure-cli 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/generator.js +1 -3
- package/package.json +1 -1
- package/templates/clean-architecture/js/src/domain/models/User.js.ejs +1 -1
- package/templates/clean-architecture/js/src/errors/ApiError.js +1 -1
- package/templates/clean-architecture/js/src/errors/BadRequestError.js +4 -4
- package/templates/clean-architecture/js/src/errors/NotFoundError.js +4 -4
- package/templates/clean-architecture/js/src/index.js.ejs +6 -8
- package/templates/clean-architecture/js/src/infrastructure/config/env.js.ejs +5 -6
- package/templates/clean-architecture/js/src/infrastructure/log/logger.js +3 -3
- package/templates/clean-architecture/js/src/infrastructure/repositories/UserRepository.js.ejs +2 -2
- package/templates/clean-architecture/js/src/infrastructure/webserver/middleware/errorMiddleware.js +4 -4
- package/templates/clean-architecture/js/src/infrastructure/webserver/server.js.ejs +28 -21
- package/templates/clean-architecture/js/src/infrastructure/webserver/swagger.js.ejs +7 -3
- package/templates/clean-architecture/js/src/interfaces/controllers/userController.js.ejs +12 -12
- package/templates/clean-architecture/js/src/interfaces/controllers/userController.spec.js.ejs +13 -15
- package/templates/clean-architecture/js/src/interfaces/graphql/context.js.ejs +2 -2
- package/templates/clean-architecture/js/src/interfaces/graphql/index.js.ejs +4 -4
- package/templates/clean-architecture/js/src/interfaces/graphql/resolvers/index.js.ejs +3 -3
- package/templates/clean-architecture/js/src/interfaces/graphql/resolvers/user.resolvers.js.ejs +2 -2
- package/templates/clean-architecture/js/src/interfaces/graphql/typeDefs/index.js.ejs +3 -3
- package/templates/clean-architecture/js/src/interfaces/graphql/typeDefs/user.types.js.ejs +1 -3
- package/templates/clean-architecture/js/src/interfaces/routes/api.js.ejs +6 -6
- package/templates/clean-architecture/js/src/usecases/CreateUser.js.ejs +2 -2
- package/templates/clean-architecture/js/src/usecases/DeleteUser.js +1 -1
- package/templates/clean-architecture/js/src/usecases/GetAllUsers.js +1 -1
- package/templates/clean-architecture/js/src/usecases/GetAllUsers.spec.js.ejs +5 -5
- package/templates/clean-architecture/js/src/usecases/UpdateUser.js.ejs +1 -1
- package/templates/clean-architecture/js/src/utils/errorMessages.js +1 -1
- package/templates/clean-architecture/js/src/utils/httpCodes.js +1 -1
- package/templates/common/SECURITY.md +18 -0
- package/templates/common/caching/clean/js/CreateUser.js.ejs +5 -5
- package/templates/common/caching/clean/js/DeleteUser.js.ejs +4 -4
- package/templates/common/caching/clean/js/GetAllUsers.js.ejs +4 -4
- package/templates/common/caching/clean/js/UpdateUser.js.ejs +4 -4
- package/templates/common/caching/js/memoryCache.js.ejs +3 -3
- package/templates/common/caching/js/redisClient.js.ejs +6 -4
- package/templates/common/ecosystem.config.js.ejs +1 -1
- package/templates/common/health/js/healthRoute.spec.js.ejs +10 -9
- package/templates/common/jest.config.js.ejs +1 -1
- package/templates/common/jest.e2e.config.js.ejs +4 -3
- package/templates/common/kafka/js/config/kafka.js +3 -3
- package/templates/common/kafka/js/messaging/baseConsumer.js.ejs +2 -2
- package/templates/common/kafka/js/messaging/userEventSchema.js.ejs +3 -3
- package/templates/common/kafka/js/messaging/welcomeEmailConsumer.js.ejs +6 -6
- package/templates/common/kafka/js/services/kafkaService.js.ejs +5 -7
- package/templates/common/kafka/js/utils/kafkaEvents.js.ejs +1 -3
- package/templates/common/migrate-mongo-config.js.ejs +2 -2
- package/templates/common/migrations/init.js.ejs +18 -20
- package/templates/common/scripts/run-e2e.js.ejs +6 -3
- package/templates/common/src/dummy.ts +3 -0
- package/templates/common/src/tests/e2e/e2e.users.test.js.ejs +1 -1
- package/templates/common/src/utils/errorMiddleware.spec.js.ejs +5 -6
- package/templates/common/tsconfig.json +2 -1
- package/templates/mvc/js/src/controllers/userController.spec.js.ejs +12 -12
- package/templates/mvc/js/src/errors/ApiError.js +1 -1
- package/templates/mvc/js/src/errors/BadRequestError.js +4 -4
- package/templates/mvc/js/src/errors/BadRequestError.spec.js.ejs +4 -4
- package/templates/mvc/js/src/errors/NotFoundError.js +4 -4
- package/templates/mvc/js/src/errors/NotFoundError.spec.js.ejs +4 -4
- package/templates/mvc/js/src/graphql/context.js.ejs +1 -1
- package/templates/mvc/js/src/graphql/index.js.ejs +4 -4
- package/templates/mvc/js/src/graphql/resolvers/index.js.ejs +3 -3
- package/templates/mvc/js/src/graphql/resolvers/user.resolvers.js.ejs +2 -2
- package/templates/mvc/js/src/graphql/typeDefs/index.js.ejs +3 -3
- package/templates/mvc/js/src/graphql/typeDefs/user.types.js.ejs +2 -2
- package/templates/mvc/js/src/routes/api.spec.js.ejs +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import NodeCache from 'node-cache';
|
|
2
|
+
import logger from '<%- loggerPath %>.js';
|
|
3
3
|
|
|
4
4
|
class MemoryCacheService {
|
|
5
5
|
constructor() {
|
|
@@ -57,4 +57,4 @@ class MemoryCacheService {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
export default MemoryCacheService.getInstance();
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import Redis from 'ioredis';
|
|
2
|
+
import dotenv from 'dotenv';
|
|
3
|
+
import logger from '<%- loggerPath %>.js';
|
|
4
|
+
|
|
5
|
+
dotenv.config();
|
|
4
6
|
|
|
5
7
|
class RedisService {
|
|
6
8
|
constructor() {
|
|
@@ -72,4 +74,4 @@ class RedisService {
|
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
export default RedisService.getInstance();
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import request from 'supertest';
|
|
2
|
+
import express from 'express';
|
|
3
3
|
<% if (architecture === 'MVC') { -%>
|
|
4
|
-
|
|
4
|
+
import healthRoute from '@/routes/healthRoute.js';
|
|
5
5
|
<% } else { -%>
|
|
6
|
-
|
|
6
|
+
import healthRoute from '@/interfaces/routes/healthRoute.js';
|
|
7
7
|
<% } -%>
|
|
8
|
-
|
|
8
|
+
import HTTP_STATUS from '@/utils/httpCodes.js';
|
|
9
9
|
|
|
10
10
|
<%_ if (database === 'MongoDB') { -%>
|
|
11
|
+
import mongoose from 'mongoose';
|
|
11
12
|
jest.mock('mongoose', () => {
|
|
12
13
|
return {
|
|
13
14
|
connection: {
|
|
@@ -21,9 +22,11 @@ jest.mock('mongoose', () => {
|
|
|
21
22
|
};
|
|
22
23
|
});
|
|
23
24
|
<%_ } else if (database !== 'None') { -%>
|
|
24
|
-
|
|
25
|
+
import sequelize from '<% if (architecture === "MVC") { %>@/config/database.js<% } else { %>@/infrastructure/database/database.js<% } %>';
|
|
26
|
+
jest.mock('<% if (architecture === "MVC") { %>@/config/database.js<% } else { %>@/infrastructure/database/database.js<% } %>', () => {
|
|
25
27
|
return {
|
|
26
|
-
authenticate: jest.fn()
|
|
28
|
+
authenticate: jest.fn(),
|
|
29
|
+
sync: jest.fn()
|
|
27
30
|
};
|
|
28
31
|
});
|
|
29
32
|
<%_ } -%>
|
|
@@ -46,7 +49,6 @@ describe('Health Route', () => {
|
|
|
46
49
|
|
|
47
50
|
<%_ if (database === 'MongoDB') { -%>
|
|
48
51
|
it('should handle database ping failure and return 500', async () => {
|
|
49
|
-
const mongoose = require('mongoose');
|
|
50
52
|
mongoose.connection.db.admin.mockReturnValueOnce({
|
|
51
53
|
ping: jest.fn().mockRejectedValueOnce(new Error('DB Error'))
|
|
52
54
|
});
|
|
@@ -58,7 +60,6 @@ describe('Health Route', () => {
|
|
|
58
60
|
});
|
|
59
61
|
<%_ } else if (database !== 'None') { -%>
|
|
60
62
|
it('should handle database authentication failure and return 500', async () => {
|
|
61
|
-
const sequelize = require('<% if (architecture === "MVC") { %>@/config/database<% } else { %>@/infrastructure/database/database<% } %>');
|
|
62
63
|
sequelize.authenticate.mockRejectedValueOnce(new Error('DB Error'));
|
|
63
64
|
|
|
64
65
|
const res = await request(app).get('/health');
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import baseConfig from './jest.config.js';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
...baseConfig,
|
|
4
5
|
testMatch: ['<rootDir>/tests/e2e/**/*.test.ts', '<rootDir>/tests/e2e/**/*.test.js'],
|
|
5
6
|
testPathIgnorePatterns: ['/node_modules/'],
|
|
6
7
|
testTimeout: 30000,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Kafka } from 'kafkajs';
|
|
2
|
+
import { env } from '../config/env.js';
|
|
3
3
|
|
|
4
4
|
const kafka = new Kafka({
|
|
5
5
|
clientId: 'nodejs-service',
|
|
6
6
|
brokers: [env.KAFKA_BROKER]
|
|
7
7
|
});
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
export { kafka };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { KAFKA_ACTIONS } from '<%- kafkaEventsPath %>.js';
|
|
3
3
|
|
|
4
4
|
const UserEventSchema = z.object({
|
|
5
5
|
action: z.enum(Object.values(KAFKA_ACTIONS)),
|
|
@@ -9,4 +9,4 @@ const UserEventSchema = z.object({
|
|
|
9
9
|
}),
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
export { UserEventSchema };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import BaseConsumer from '<%- baseConsumerPath %>.js';
|
|
2
|
+
import logger from '<%- loggerPath %>.js';
|
|
3
|
+
import { UserEventSchema } from '<%- userEventSchemaPath %>.js';
|
|
4
|
+
import ERROR_MESSAGES from '<%- errorMessagesPath %>.js';
|
|
5
|
+
import { KAFKA_ACTIONS } from '<%- kafkaEventsPath %>.js';
|
|
6
6
|
|
|
7
7
|
class WelcomeEmailConsumer extends BaseConsumer {
|
|
8
8
|
constructor() {
|
|
@@ -41,4 +41,4 @@ class WelcomeEmailConsumer extends BaseConsumer {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
export default WelcomeEmailConsumer;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { kafka } from '../config/kafka.js';
|
|
2
|
+
import logger from '<% if (architecture === "Clean Architecture") { %>../log/logger.js<% } else { %>../utils/logger.js<% } %>';
|
|
3
|
+
import WelcomeEmailConsumer from '<% if (architecture === "Clean Architecture") { %>../../interfaces/messaging/consumers/instances/welcomeEmailConsumer.js<% } else { %>../messaging/consumers/instances/welcomeEmailConsumer.js<% } %>';
|
|
3
4
|
|
|
4
5
|
let producer = null;
|
|
5
6
|
let consumer = null;
|
|
@@ -14,10 +15,7 @@ const connectKafka = async (retries = 10) => {
|
|
|
14
15
|
if (!consumer) consumer = kafka.consumer({ groupId: 'test-group' });
|
|
15
16
|
|
|
16
17
|
let attempt = 0;
|
|
17
|
-
|
|
18
|
-
// Note: Dynamic import used here for simplicity and to avoid startup crashes.
|
|
19
|
-
// In enterprise production, consider using Dependency Injection.
|
|
20
|
-
const WelcomeEmailConsumer = require('<% if (architecture === "Clean Architecture") { %>../../interfaces/messaging/consumers/instances/welcomeEmailConsumer<% } else { %>../messaging/consumers/instances/welcomeEmailConsumer<% } %>');
|
|
18
|
+
|
|
21
19
|
while (attempt < retries) {
|
|
22
20
|
try {
|
|
23
21
|
await producer.connect();
|
|
@@ -90,4 +88,4 @@ const disconnectKafka = async () => {
|
|
|
90
88
|
if (consumer) await consumer.disconnect();
|
|
91
89
|
};
|
|
92
90
|
|
|
93
|
-
|
|
91
|
+
export { connectKafka, sendMessage, disconnectKafka };
|
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const existingAdmin = await db.collection('users').findOne({ email: adminEmail });
|
|
1
|
+
export const up = async (db, client) => {
|
|
2
|
+
const adminEmail = 'admin@example.com';
|
|
3
|
+
const existingAdmin = await db.collection('users').findOne({ email: adminEmail });
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
async down(db, client) {
|
|
20
|
-
// Optional: Undo the seed. Usually for seeds we might want to keep data, but strictly speaking 'down' should reverse 'up'.
|
|
21
|
-
// await db.collection('users').deleteOne({ email: 'admin@example.com' });
|
|
5
|
+
if (!existingAdmin) {
|
|
6
|
+
await db.collection('users').insertOne({
|
|
7
|
+
name: 'Admin User',
|
|
8
|
+
email: adminEmail,
|
|
9
|
+
createdAt: new Date(),
|
|
10
|
+
updatedAt: new Date()
|
|
11
|
+
});
|
|
12
|
+
console.log('Admin User seeded successfully');
|
|
13
|
+
} else {
|
|
14
|
+
console.log('Admin User already exists, skipping seed');
|
|
22
15
|
}
|
|
23
16
|
};
|
|
17
|
+
|
|
18
|
+
export const down = async (db, client) => {
|
|
19
|
+
// Optional: Undo the seed. Usually for seeds we might want to keep data, but strictly speaking 'down' should reverse 'up'.
|
|
20
|
+
// await db.collection('users').deleteOne({ email: 'admin@example.com' });
|
|
21
|
+
};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = path.dirname(__filename);
|
|
4
7
|
|
|
5
8
|
// Set a specific port for E2E tests to avoid collisions with local development
|
|
6
9
|
process.env.PORT = '3001';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { errorMiddleware } from '<% if (architecture === "MVC") { %>@/utils/errorMiddleware.js<% } else { %>@/infrastructure/webserver/middleware/errorMiddleware.js<% } %>';
|
|
2
|
+
import { ApiError } from '@/errors/ApiError.js';
|
|
3
|
+
import HTTP_STATUS from '@/utils/httpCodes.js';
|
|
4
|
+
import logger from '<% if (architecture === "MVC") { %>@/utils/logger.js<% } else { %>@/infrastructure/log/logger.js<% } %>';
|
|
5
5
|
|
|
6
|
-
jest.mock('<% if (architecture === "MVC") { %>@/utils/logger<% } else { %>@/infrastructure/log/logger<% } %>');
|
|
6
|
+
jest.mock('<% if (architecture === "MVC") { %>@/utils/logger.js<% } else { %>@/infrastructure/log/logger.js<% } %>');
|
|
7
7
|
|
|
8
8
|
describe('Error Middleware', () => {
|
|
9
9
|
let mockRequest;
|
|
@@ -68,7 +68,6 @@ describe('Error Middleware', () => {
|
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
it('should handle error without stack trace', () => {
|
|
71
|
-
const { ApiError } = require('@/errors/ApiError');
|
|
72
71
|
const customError = new ApiError(500, 'No Stack', false);
|
|
73
72
|
delete customError.stack;
|
|
74
73
|
errorMiddleware(customError, mockRequest, mockResponse, nextFunction);
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import HTTP_STATUS from '@/utils/httpCodes.js';
|
|
2
|
+
import ERROR_MESSAGES from '@/utils/errorMessages.js';
|
|
3
3
|
<% if (communication !== 'GraphQL') { -%>
|
|
4
4
|
// Express-only imports would go here
|
|
5
5
|
<% } -%>
|
|
6
|
-
|
|
6
|
+
import { getUsers, createUser, updateUser, deleteUser } from '@/controllers/userController.js';
|
|
7
7
|
<%_ if (caching === 'Redis') { -%>
|
|
8
|
-
|
|
8
|
+
import cacheService from '@/config/redisClient.js';
|
|
9
9
|
<%_ } else if (caching === 'Memory Cache') { -%>
|
|
10
|
-
|
|
10
|
+
import cacheService from '@/config/memoryCache.js';
|
|
11
11
|
<%_ } -%>
|
|
12
12
|
|
|
13
13
|
// Mock dependencies
|
|
14
|
-
jest.mock('@/models/User', () => {
|
|
14
|
+
jest.mock('@/models/User.js', () => {
|
|
15
15
|
return {
|
|
16
16
|
create: jest.fn(),
|
|
17
17
|
find: jest.fn(),
|
|
@@ -25,23 +25,23 @@ jest.mock('@/models/User', () => {
|
|
|
25
25
|
mockData: []
|
|
26
26
|
};
|
|
27
27
|
});
|
|
28
|
-
|
|
28
|
+
import User from '@/models/User.js';
|
|
29
29
|
<%_ if (caching === 'Redis') { -%>
|
|
30
|
-
jest.mock('@/config/redisClient', () => ({
|
|
30
|
+
jest.mock('@/config/redisClient.js', () => ({
|
|
31
31
|
getOrSet: jest.fn((_key, fetcher) => fetcher()),
|
|
32
32
|
del: jest.fn(),
|
|
33
33
|
flush: jest.fn()
|
|
34
34
|
}));
|
|
35
35
|
<%_ } else if (caching === 'Memory Cache') { -%>
|
|
36
|
-
jest.mock('@/config/memoryCache', () => ({
|
|
36
|
+
jest.mock('@/config/memoryCache.js', () => ({
|
|
37
37
|
getOrSet: jest.fn((_key, fetcher) => fetcher()),
|
|
38
38
|
del: jest.fn(),
|
|
39
39
|
flush: jest.fn()
|
|
40
40
|
}));
|
|
41
41
|
<%_ } -%>
|
|
42
|
-
jest.mock('@/utils/logger');
|
|
42
|
+
jest.mock('@/utils/logger.js');
|
|
43
43
|
<%_ if (communication === 'Kafka') { -%>
|
|
44
|
-
jest.mock('@/services/kafkaService', () => {
|
|
44
|
+
jest.mock('@/services/kafkaService.js', () => {
|
|
45
45
|
const mockSendMessage = jest.fn().mockResolvedValue(undefined);
|
|
46
46
|
return {
|
|
47
47
|
sendMessage: mockSendMessage,
|
|
@@ -53,7 +53,7 @@ jest.mock('@/services/kafkaService', () => {
|
|
|
53
53
|
}))
|
|
54
54
|
};
|
|
55
55
|
});
|
|
56
|
-
|
|
56
|
+
import { sendMessage } from '@/services/kafkaService.js';
|
|
57
57
|
<%_ } -%>
|
|
58
58
|
|
|
59
59
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ApiError } from './ApiError.js';
|
|
2
|
+
import HTTP_STATUS from '../utils/httpCodes.js';
|
|
3
|
+
import ERROR_MESSAGES from '../utils/errorMessages.js';
|
|
4
4
|
|
|
5
5
|
class BadRequestError extends ApiError {
|
|
6
6
|
constructor(message = ERROR_MESSAGES.BAD_REQUEST) {
|
|
@@ -8,4 +8,4 @@ class BadRequestError extends ApiError {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
export { BadRequestError };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { BadRequestError } from '@/errors/BadRequestError.js';
|
|
2
|
+
import { ApiError } from '@/errors/ApiError.js';
|
|
3
|
+
import HTTP_STATUS from '@/utils/httpCodes.js';
|
|
4
|
+
import ERROR_MESSAGES from '@/utils/errorMessages.js';
|
|
5
5
|
|
|
6
6
|
describe('BadRequestError', () => {
|
|
7
7
|
it('should extend ApiError', () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ApiError } from './ApiError.js';
|
|
2
|
+
import HTTP_STATUS from '../utils/httpCodes.js';
|
|
3
|
+
import ERROR_MESSAGES from '../utils/errorMessages.js';
|
|
4
4
|
|
|
5
5
|
class NotFoundError extends ApiError {
|
|
6
6
|
constructor(message = ERROR_MESSAGES.RESOURCE_NOT_FOUND) {
|
|
@@ -8,4 +8,4 @@ class NotFoundError extends ApiError {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
export { NotFoundError };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { NotFoundError } from '@/errors/NotFoundError.js';
|
|
2
|
+
import { ApiError } from '@/errors/ApiError.js';
|
|
3
|
+
import HTTP_STATUS from '@/utils/httpCodes.js';
|
|
4
|
+
import ERROR_MESSAGES from '@/utils/errorMessages.js';
|
|
5
5
|
|
|
6
6
|
describe('NotFoundError', () => {
|
|
7
7
|
it('should extend ApiError', () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { typeDefs } from './typeDefs/index.js';
|
|
2
|
+
import { resolvers } from './resolvers/index.js';
|
|
3
|
+
import { gqlContext } from './context.js';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
export { typeDefs, resolvers, gqlContext };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { mergeResolvers } from '@graphql-tools/merge';
|
|
2
|
+
import { userResolvers } from './user.resolvers.js';
|
|
3
3
|
|
|
4
4
|
const resolvers = mergeResolvers([userResolvers]);
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
export { resolvers };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import * as userController from '../../controllers/userController.js';
|
|
2
2
|
|
|
3
3
|
const userResolvers = {
|
|
4
4
|
Query: {
|
|
@@ -22,4 +22,4 @@ const userResolvers = {
|
|
|
22
22
|
}<%_ } %>
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
export { userResolvers };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { mergeTypeDefs } from '@graphql-tools/merge';
|
|
2
|
+
import { userTypes } from './user.types.js';
|
|
3
3
|
|
|
4
4
|
const typeDefs = mergeTypeDefs([userTypes]);
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
export { typeDefs };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import request from 'supertest';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import router from '@/routes/api.js';
|
|
4
4
|
|
|
5
5
|
const mockGetUsers = jest.fn().mockImplementation((req, res) => res.status(200).json([{ id: '1', name: 'John Doe' }]));
|
|
6
6
|
const mockCreateUser = jest.fn().mockImplementation((req, res) => res.status(201).json({ id: '1', name: 'Test' }));
|
|
@@ -8,7 +8,7 @@ const mockCreateUser = jest.fn().mockImplementation((req, res) => res.status(201
|
|
|
8
8
|
const mockUpdateUser = jest.fn().mockImplementation((req, res) => res.status(200).json({ id: '1', name: 'Updated' }));
|
|
9
9
|
const mockDeleteUser = jest.fn().mockImplementation((req, res) => res.status(200).json({ message: 'User deleted successfully' }));
|
|
10
10
|
|
|
11
|
-
jest.mock('@/controllers/userController', () => ({
|
|
11
|
+
jest.mock('@/controllers/userController.js', () => ({
|
|
12
12
|
getUsers: (...args) => mockGetUsers(...args),
|
|
13
13
|
createUser: (...args) => mockCreateUser(...args),
|
|
14
14
|
updateUser: (...args) => mockUpdateUser(...args),
|