@anthonylzq/simba.js 9.0.1 → 9.1.0
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/README.md +59 -30
- package/lib/index.js +42 -5
- package/lib/src/functions/api/database.js +40 -218
- package/lib/src/functions/api/express.js +100 -604
- package/lib/src/functions/api/fastify.js +93 -645
- package/lib/src/functions/api/hono.js +157 -0
- package/lib/src/functions/api/index.js +37 -59
- package/lib/src/functions/api/schemas.js +20 -84
- package/lib/src/functions/api/services.js +28 -210
- package/lib/src/functions/api/utils.js +10 -432
- package/lib/src/functions/biome.js +3 -2
- package/lib/src/functions/changelog.js +5 -5
- package/lib/src/functions/docker.js +7 -39
- package/lib/src/functions/ghat.js +12 -94
- package/lib/src/functions/gitignore.js +3 -134
- package/lib/src/functions/index.js +1 -2
- package/lib/src/functions/license.js +10 -2
- package/lib/src/functions/packageJson.js +13 -37
- package/lib/src/functions/readme.js +6 -5
- package/lib/src/functions/tests.js +17 -320
- package/lib/src/functions/tsconfig.js +13 -114
- package/lib/src/index.js +45 -21
- package/lib/src/utils/entity.js +115 -0
- package/lib/src/utils/index.js +2 -0
- package/lib/src/utils/mkdirs.js +9 -0
- package/lib/src/utils/renderTemplate.js +22 -0
- package/lib/src/utils/titleCase.js +5 -10
- package/lib/src/utils/writeFile.js +3 -10
- package/lib/templates/api/database/connection.ts.ejs +40 -0
- package/lib/templates/api/database/db-index.ts.ejs +2 -0
- package/lib/templates/api/database/index.ts.ejs +1 -0
- package/lib/templates/api/database/queries-entity.ts.ejs +98 -0
- package/lib/templates/api/database/queries-index.ts.ejs +1 -0
- package/lib/templates/api/database/schema.prisma.ejs +25 -0
- package/lib/templates/api/express/network/index.ts.ejs +2 -0
- package/lib/templates/api/express/network/models/entity.ts.ejs +21 -0
- package/lib/templates/api/express/network/models/index.ts.ejs +1 -0
- package/lib/templates/api/express/network/resolvers/entity.ts.ejs +41 -0
- package/lib/templates/api/express/network/resolvers/index.ts.ejs +13 -0
- package/lib/templates/api/express/network/response.ts.ejs +17 -0
- package/lib/templates/api/express/network/router.ts.ejs +39 -0
- package/lib/templates/api/express/network/routes/docs.ts.ejs +43 -0
- package/lib/templates/api/express/network/routes/entity.ts.ejs +165 -0
- package/lib/templates/api/express/network/routes/home.ts.ejs +16 -0
- package/lib/templates/api/express/network/routes/index.ts.ejs +5 -0
- package/lib/templates/api/express/network/server.ts.ejs +139 -0
- package/lib/templates/api/express/network/utils/index.ts.ejs +45 -0
- package/lib/templates/api/express/types/graphQL/context.d.ts.ejs +3 -0
- package/lib/templates/api/express/types/index.d.ts.ejs +4 -0
- package/lib/templates/api/fastify/network/index.ts.ejs +2 -0
- package/lib/templates/api/fastify/network/models/entity.ts.ejs +21 -0
- package/lib/templates/api/fastify/network/models/index.ts.ejs +1 -0
- package/lib/templates/api/fastify/network/resolvers/entity.ts.ejs +41 -0
- package/lib/templates/api/fastify/network/resolvers/index.ts.ejs +13 -0
- package/lib/templates/api/fastify/network/response.ts.ejs +17 -0
- package/lib/templates/api/fastify/network/router.ts.ejs +36 -0
- package/lib/templates/api/fastify/network/routes/docs.ts.ejs +41 -0
- package/lib/templates/api/fastify/network/routes/entity.ts.ejs +116 -0
- package/lib/templates/api/fastify/network/routes/home.ts.ejs +15 -0
- package/lib/templates/api/fastify/network/routes/index.ts.ejs +5 -0
- package/lib/templates/api/fastify/network/server.ts.ejs +129 -0
- package/lib/templates/api/fastify/types/graphQL/context.d.ts.ejs +3 -0
- package/lib/templates/api/fastify/types/index.d.ts.ejs +4 -0
- package/lib/templates/api/hono/network/index.ts.ejs +2 -0
- package/lib/templates/api/hono/network/models/entity.ts.ejs +21 -0
- package/lib/templates/api/hono/network/models/index.ts.ejs +1 -0
- package/lib/templates/api/hono/network/resolvers/entity.ts.ejs +41 -0
- package/lib/templates/api/hono/network/resolvers/index.ts.ejs +13 -0
- package/lib/templates/api/hono/network/response.ts.ejs +18 -0
- package/lib/templates/api/hono/network/router.ts.ejs +45 -0
- package/lib/templates/api/hono/network/routes/docs.ts.ejs +39 -0
- package/lib/templates/api/hono/network/routes/entity.ts.ejs +104 -0
- package/lib/templates/api/hono/network/routes/home.ts.ejs +15 -0
- package/lib/templates/api/hono/network/routes/index.ts.ejs +5 -0
- package/lib/templates/api/hono/network/server.ts.ejs +160 -0
- package/lib/templates/api/hono/network/utils/index.ts.ejs +23 -0
- package/lib/templates/api/hono/types/graphQL/context.d.ts.ejs +3 -0
- package/lib/templates/api/hono/types/index.d.ts.ejs +4 -0
- package/lib/templates/api/schemas/entity.ts.ejs +43 -0
- package/lib/templates/api/schemas/id.ts.ejs +11 -0
- package/lib/templates/api/schemas/index.ts.ejs +2 -0
- package/lib/templates/api/services/BaseHttp.ts.ejs +73 -0
- package/lib/templates/api/services/entity.ts.ejs +75 -0
- package/lib/templates/api/services/index.ts.ejs +1 -0
- package/lib/templates/api/services/utils/index.ts.ejs +1 -0
- package/lib/templates/api/services/utils/messages/entity.ts.ejs +11 -0
- package/lib/templates/api/services/utils/messages/index.ts.ejs +6 -0
- package/lib/templates/api/utils/Logger.ts.ejs +41 -0
- package/lib/templates/api/utils/index.ts.ejs +1 -0
- package/lib/templates/config/.dockerignore.ejs +20 -0
- package/lib/templates/config/.env.ejs +3 -0
- package/lib/templates/config/.gitignore.ejs +129 -0
- package/lib/templates/config/CHANGELOG.md.ejs +1 -0
- package/lib/templates/config/Dockerfile.ejs +13 -0
- package/lib/templates/config/README.md.ejs +3 -0
- package/lib/templates/config/ghat/lint.yml.ejs +46 -0
- package/lib/templates/config/ghat/test.yml.ejs +29 -0
- package/lib/templates/config/index.ts.ejs +3 -0
- package/lib/templates/config/package.json.ejs +30 -0
- package/lib/templates/config/test/index.test.ts.ejs +260 -0
- package/lib/templates/config/tsconfig.base.json.ejs +43 -0
- package/lib/templates/config/tsconfig.json.ejs +16 -0
- package/lib/templates/config/vitest.config.ts.ejs +19 -0
- package/package.json +45 -17
- package/lib/src/functions/api/types.js +0 -108
- package/lib/src/functions/eslint.js +0 -125
|
@@ -1,143 +1,12 @@
|
|
|
1
1
|
const writeFile = require('../utils/writeFile')
|
|
2
|
+
const { renderTemplate } = require('../utils/renderTemplate')
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @param {String} projectName
|
|
5
6
|
* @returns {Promise<void>}
|
|
6
7
|
*/
|
|
7
8
|
module.exports = async projectName => {
|
|
8
|
-
const
|
|
9
|
-
gitignoreContent: `# Created by https://www.toptal.com/developers/gitignore/api/node,yarn
|
|
10
|
-
# Edit at https://www.toptal.com/developers/gitignore?templates=node,yarn
|
|
9
|
+
const content = renderTemplate('config/.gitignore.ejs')
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
# Logs
|
|
14
|
-
logs
|
|
15
|
-
*.log
|
|
16
|
-
npm-debug.log*
|
|
17
|
-
yarn-debug.log*
|
|
18
|
-
yarn-error.log*
|
|
19
|
-
lerna-debug.log*
|
|
20
|
-
|
|
21
|
-
# Diagnostic reports (https://nodejs.org/api/report.html)
|
|
22
|
-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
23
|
-
|
|
24
|
-
# Runtime data
|
|
25
|
-
pids
|
|
26
|
-
*.pid
|
|
27
|
-
*.seed
|
|
28
|
-
*.pid.lock
|
|
29
|
-
|
|
30
|
-
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
31
|
-
lib-cov
|
|
32
|
-
|
|
33
|
-
# Coverage directory used by tools like istanbul
|
|
34
|
-
coverage
|
|
35
|
-
*.lcov
|
|
36
|
-
|
|
37
|
-
# nyc test coverage
|
|
38
|
-
.nyc_output
|
|
39
|
-
|
|
40
|
-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
|
41
|
-
.grunt
|
|
42
|
-
|
|
43
|
-
# Bower dependency directory (https://bower.io/)
|
|
44
|
-
bower_components
|
|
45
|
-
|
|
46
|
-
# node-waf configuration
|
|
47
|
-
.lock-wscript
|
|
48
|
-
|
|
49
|
-
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
|
50
|
-
build/Release
|
|
51
|
-
|
|
52
|
-
# Dependency directories
|
|
53
|
-
node_modules/
|
|
54
|
-
jspm_packages/
|
|
55
|
-
|
|
56
|
-
# TypeScript v1 declaration files
|
|
57
|
-
typings/
|
|
58
|
-
|
|
59
|
-
# TypeScript cache
|
|
60
|
-
*.tsbuildinfo
|
|
61
|
-
|
|
62
|
-
# Optional npm cache directory
|
|
63
|
-
.npm
|
|
64
|
-
|
|
65
|
-
# Optional eslint cache
|
|
66
|
-
.eslintcache
|
|
67
|
-
|
|
68
|
-
# Microbundle cache
|
|
69
|
-
.rpt2_cache/
|
|
70
|
-
.rts2_cache_cjs/
|
|
71
|
-
.rts2_cache_es/
|
|
72
|
-
.rts2_cache_umd/
|
|
73
|
-
|
|
74
|
-
# Optional REPL history
|
|
75
|
-
.node_repl_history
|
|
76
|
-
|
|
77
|
-
# Output of 'npm pack'
|
|
78
|
-
*.tgz
|
|
79
|
-
|
|
80
|
-
# Yarn Integrity file
|
|
81
|
-
.yarn-integrity
|
|
82
|
-
|
|
83
|
-
# dotenv environment variables file
|
|
84
|
-
.env
|
|
85
|
-
|
|
86
|
-
# parcel-bundler cache (https://parceljs.org/)
|
|
87
|
-
.cache
|
|
88
|
-
|
|
89
|
-
# Next.js build output
|
|
90
|
-
.next
|
|
91
|
-
|
|
92
|
-
# Nuxt.js build / generate output
|
|
93
|
-
.nuxt
|
|
94
|
-
|
|
95
|
-
# Gatsby files
|
|
96
|
-
.cache/
|
|
97
|
-
# Comment in the public line in if your project uses Gatsby and not Next.js
|
|
98
|
-
# https://nextjs.org/blog/next-9-1#public-directory-support
|
|
99
|
-
# public
|
|
100
|
-
|
|
101
|
-
# vuepress build output
|
|
102
|
-
.vuepress/dist
|
|
103
|
-
|
|
104
|
-
# Serverless directories
|
|
105
|
-
.serverless/
|
|
106
|
-
|
|
107
|
-
# FuseBox cache
|
|
108
|
-
.fusebox/
|
|
109
|
-
|
|
110
|
-
# DynamoDB Local files
|
|
111
|
-
.dynamodb/
|
|
112
|
-
|
|
113
|
-
# TernJS port file
|
|
114
|
-
.tern-port
|
|
115
|
-
|
|
116
|
-
# Stores VSCode versions used for testing VSCode extensions
|
|
117
|
-
.vscode*
|
|
118
|
-
|
|
119
|
-
### yarn ###
|
|
120
|
-
# https://yarnpkg.com/advanced/qa#which-files-should-be-gitignored
|
|
121
|
-
|
|
122
|
-
# .yarn/unplugged and .yarn/build-state.yml should likely always be ignored since
|
|
123
|
-
# they typically hold machine-specific build artifacts. Ignoring them might however
|
|
124
|
-
# prevent Zero-Installs from working (to prevent this, set enableScripts to false).
|
|
125
|
-
.yarn/unplugged
|
|
126
|
-
.yarn/build-state.yml
|
|
127
|
-
|
|
128
|
-
# .yarn/cache and .pnp.* may be safely ignored, but you'll need to run yarn install
|
|
129
|
-
# to regenerate them between each branch switch.
|
|
130
|
-
# Uncomment the following lines if you're not using Zero-Installs:
|
|
131
|
-
# .yarn/cache
|
|
132
|
-
# .pnp.*
|
|
133
|
-
|
|
134
|
-
# End of https://www.toptal.com/developers/gitignore/api/node,yarn
|
|
135
|
-
|
|
136
|
-
dist
|
|
137
|
-
test/setEnvVars.ts
|
|
138
|
-
`,
|
|
139
|
-
gitignoreFile: '.gitignore'
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
await writeFile(`${projectName}/${data.gitignoreFile}`, data.gitignoreContent)
|
|
11
|
+
await writeFile(`${projectName}/.gitignore`, content)
|
|
143
12
|
}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
const https = require('node:https')
|
|
2
|
-
const _ = require('underscore')
|
|
3
2
|
const writeFile = require('../utils/writeFile')
|
|
4
3
|
|
|
4
|
+
const htmlUnescape = str =>
|
|
5
|
+
str
|
|
6
|
+
.replace(/&/g, '&')
|
|
7
|
+
.replace(/</g, '<')
|
|
8
|
+
.replace(/>/g, '>')
|
|
9
|
+
.replace(/"/g, '"')
|
|
10
|
+
.replace(/'/g, "'")
|
|
11
|
+
.replace(/`/g, '`')
|
|
12
|
+
|
|
5
13
|
/**
|
|
6
14
|
* @param {LicenseConfig} config
|
|
7
15
|
* @returns {Promise<String>}
|
|
@@ -17,7 +25,7 @@ const getLicense = ({ author, license, year, projectDescription }) => {
|
|
|
17
25
|
res.on('end', () => {
|
|
18
26
|
const begin = result.indexOf('id="license-text"')
|
|
19
27
|
const end = result.indexOf('</pre>')
|
|
20
|
-
result =
|
|
28
|
+
result = htmlUnescape(result.slice(begin + 18, end))
|
|
21
29
|
|
|
22
30
|
switch (license) {
|
|
23
31
|
case 'mit':
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const writeFile = require('../utils/writeFile')
|
|
2
|
+
const { renderTemplate } = require('../utils/renderTemplate')
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @param {PackageConfig} packageConfig
|
|
@@ -12,46 +13,21 @@ module.exports = async ({
|
|
|
12
13
|
license,
|
|
13
14
|
mainFile
|
|
14
15
|
}) => {
|
|
15
|
-
const
|
|
16
|
-
content: `{
|
|
17
|
-
"name": "${projectName
|
|
16
|
+
const sanitizedName = projectName
|
|
18
17
|
.toLowerCase()
|
|
19
18
|
.replaceAll(' ', '-')
|
|
20
|
-
.replaceAll('/', '-')
|
|
21
|
-
"version": "${projectVersion}",
|
|
22
|
-
"main": "${mainFile}",
|
|
23
|
-
"description": "${projectDescription}",
|
|
24
|
-
"scripts": {
|
|
25
|
-
"lint": "biome check --write src/",
|
|
26
|
-
"service": "nodemon",
|
|
27
|
-
"start": "ts-node src/index.ts",
|
|
28
|
-
"release": "standard-version",
|
|
29
|
-
"test:ci": "jest --ci -i",
|
|
30
|
-
"test:local": "NODE_ENV=local jest --ci -i --setupFiles dotenv/config"
|
|
31
|
-
},
|
|
32
|
-
"author": "${author}",${
|
|
33
|
-
license !== 'unlicensed'
|
|
34
|
-
? `\n "license": "${license.toUpperCase()}",\n`
|
|
35
|
-
: ''
|
|
36
|
-
}
|
|
37
|
-
"dependencies": {},
|
|
38
|
-
"devDependencies": {},
|
|
39
|
-
"nodemonConfig": {
|
|
40
|
-
"watch": [
|
|
41
|
-
".env",
|
|
42
|
-
"src"
|
|
43
|
-
],
|
|
44
|
-
"ext": "ts",
|
|
45
|
-
"ignore": [
|
|
46
|
-
"src/**/*.test.ts"
|
|
47
|
-
],
|
|
48
|
-
"exec": "DEBUG=App:* npx ts-node -r dotenv/config ./src/index"
|
|
49
|
-
}
|
|
50
|
-
}\n`,
|
|
51
|
-
file: 'package.json'
|
|
52
|
-
}
|
|
19
|
+
.replaceAll('/', '-')
|
|
53
20
|
|
|
54
|
-
|
|
21
|
+
const content = renderTemplate('config/package.json.ejs', {
|
|
22
|
+
sanitizedName,
|
|
23
|
+
projectVersion,
|
|
24
|
+
mainFile,
|
|
25
|
+
projectDescription,
|
|
26
|
+
author,
|
|
27
|
+
license
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
await writeFile(`${projectName}/package.json`, content)
|
|
55
31
|
}
|
|
56
32
|
|
|
57
33
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const writeFile = require('../utils/writeFile')
|
|
2
2
|
const titleCase = require('../utils/titleCase')
|
|
3
|
+
const { renderTemplate } = require('../utils/renderTemplate')
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* @param {String} projectName
|
|
@@ -7,10 +8,10 @@ const titleCase = require('../utils/titleCase')
|
|
|
7
8
|
* @returns {Promise<void>}
|
|
8
9
|
*/
|
|
9
10
|
module.exports = async (projectName, projectDescription) => {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
11
|
+
const content = renderTemplate('config/README.md.ejs', {
|
|
12
|
+
titleCaseName: titleCase(projectName),
|
|
13
|
+
projectDescription
|
|
14
|
+
})
|
|
14
15
|
|
|
15
|
-
await writeFile(`${projectName}
|
|
16
|
+
await writeFile(`${projectName}/README.md`, content)
|
|
16
17
|
}
|
|
@@ -1,333 +1,30 @@
|
|
|
1
|
-
const
|
|
2
|
-
const { promisify } = require('node:util')
|
|
3
|
-
const exec = promisify(require('node:child_process').exec)
|
|
1
|
+
const mkdirs = require('../utils/mkdirs')
|
|
4
2
|
const writeFile = require('../utils/writeFile')
|
|
3
|
+
const { renderTemplate } = require('../utils/renderTemplate')
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* @param {Object} args
|
|
8
7
|
* @param {String} args.projectName
|
|
9
8
|
* @param {Boolean} args.graphql
|
|
10
9
|
* @param {Boolean} args.dbIsSQL
|
|
10
|
+
* @param {import('../../utils/entity').EntityContext} args.entityContext
|
|
11
11
|
* @returns {Promise<void>}
|
|
12
12
|
*/
|
|
13
|
-
module.exports = async ({ projectName, graphql, dbIsSQL }) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (platform() === 'win32')
|
|
17
|
-
await exec(createFoldersCommand.replaceAll('/', '\\'))
|
|
18
|
-
else await exec(createFoldersCommand)
|
|
19
|
-
|
|
20
|
-
const data = {
|
|
21
|
-
jestConfig: {
|
|
22
|
-
content: `import { Config } from '@jest/types'
|
|
23
|
-
|
|
24
|
-
const config: Config.InitialOptions = {
|
|
25
|
-
verbose: true,
|
|
26
|
-
preset: 'ts-jest',
|
|
27
|
-
testEnvironment: 'node',
|
|
28
|
-
testTimeout: 1 * 60 * 1000,
|
|
29
|
-
modulePaths: ['<rootDir>/src', '<rootDir>/node_modules'],
|
|
30
|
-
roots: ['.'],
|
|
31
|
-
moduleFileExtensions: ['js', 'json', 'ts'],
|
|
32
|
-
testRegex: '.test.ts$',
|
|
33
|
-
transform: {
|
|
34
|
-
'^.+\\\\.(t|j)s$': 'ts-jest'
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export default config
|
|
39
|
-
`,
|
|
40
|
-
file: `${projectName}/jest.config.ts`
|
|
41
|
-
},
|
|
42
|
-
test: {
|
|
43
|
-
index: {
|
|
44
|
-
content: graphql
|
|
45
|
-
? `import axios from 'axios'
|
|
46
|
-
import z from 'zod'
|
|
47
|
-
|
|
48
|
-
import { Server } from '../src/network'
|
|
49
|
-
import { userDto } from '../src/schemas'
|
|
50
|
-
|
|
51
|
-
const BASE_URL = \`http://localhost:\${process.env.PORT || 1996}\`
|
|
52
|
-
const baseResponseDto = z.object({
|
|
53
|
-
error: z.boolean(),
|
|
54
|
-
message: z.string()
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
type BaseResponseDTO = z.infer<typeof baseResponseDto>
|
|
58
|
-
|
|
59
|
-
describe('Simba.js tests', () => {
|
|
60
|
-
beforeAll(async () => {
|
|
61
|
-
await Server.start()
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
describe('API endpoints tests', () => {
|
|
65
|
-
let userID = ${dbIsSQL ? 0 : "''"}
|
|
66
|
-
|
|
67
|
-
describe('API: GET /', () => {
|
|
68
|
-
it('Should return 200 with a successful operation', async () => {
|
|
69
|
-
const result = await axios.get<BaseResponseDTO>(BASE_URL)
|
|
70
|
-
|
|
71
|
-
expect(result.status).toBe(200)
|
|
72
|
-
expect(result.data.error).toBe(false)
|
|
73
|
-
expect(baseResponseDto.parse(result.data).error).toBe(false)
|
|
74
|
-
})
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
describe('API: storeUser mutation', () => {
|
|
78
|
-
const storeUserResponse = z.object({
|
|
79
|
-
data: z.object({
|
|
80
|
-
user: userDto
|
|
81
|
-
})
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
type StoreUserDTO = z.infer<typeof storeUserResponse>
|
|
85
|
-
|
|
86
|
-
it('Should create a user successfully', async () => {
|
|
87
|
-
const result = await axios.post<StoreUserDTO>(\`\${BASE_URL}/graphql\`, {
|
|
88
|
-
query: \`mutation store($user: UserInput!) {
|
|
89
|
-
user: store(user: $user) {
|
|
90
|
-
id
|
|
91
|
-
name
|
|
92
|
-
lastName
|
|
93
|
-
createdAt
|
|
94
|
-
updatedAt
|
|
95
|
-
}
|
|
96
|
-
}\`,
|
|
97
|
-
variables: {
|
|
98
|
-
user: {
|
|
99
|
-
lastName: 'Lzq',
|
|
100
|
-
name: 'Anthony'
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
userID = result.data.data.user.id ?? userID
|
|
106
|
-
expect(userID).toBeTruthy()
|
|
107
|
-
expect(result.status).toBe(200)
|
|
108
|
-
expect(storeUserResponse.safeParse(result.data).success).toBe(true)
|
|
109
|
-
})
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
describe('API: getUser query', () => {
|
|
113
|
-
const getUserResponse = z.object({
|
|
114
|
-
data: z.object({
|
|
115
|
-
user: userDto
|
|
116
|
-
})
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
type GetOneUserDTO = z.infer<typeof getUserResponse>
|
|
120
|
-
|
|
121
|
-
it('Should return a user', async () => {
|
|
122
|
-
const result = await axios.post<GetOneUserDTO>(\`\${BASE_URL}/graphql\`, {
|
|
123
|
-
query: \`query getById($id: ${dbIsSQL ? 'Float' : 'String'}!) {
|
|
124
|
-
user: getById(id: $id) {
|
|
125
|
-
id
|
|
126
|
-
name
|
|
127
|
-
lastName
|
|
128
|
-
createdAt
|
|
129
|
-
updatedAt
|
|
130
|
-
}
|
|
131
|
-
}\`,
|
|
132
|
-
variables: {
|
|
133
|
-
id: userID
|
|
134
|
-
}
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
expect(result.status).toBe(200)
|
|
138
|
-
expect(getUserResponse.safeParse(result.data).success).toBe(true)
|
|
139
|
-
})
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
describe('API: updateUser mutation', () => {
|
|
143
|
-
const updateUserResponse = z.object({
|
|
144
|
-
data: z.object({
|
|
145
|
-
user: userDto
|
|
146
|
-
})
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
type UpdateUserDTO = z.infer<typeof updateUserResponse>
|
|
150
|
-
|
|
151
|
-
it('Should update a user successfully', async () => {
|
|
152
|
-
const result = await axios.post<UpdateUserDTO>(\`\${BASE_URL}/graphql\`, {
|
|
153
|
-
query: \`mutation update($id: ${
|
|
154
|
-
dbIsSQL ? 'Float' : 'String'
|
|
155
|
-
}!, $user: UserInput!) {
|
|
156
|
-
user: update(id: $id, user: $user) {
|
|
157
|
-
id
|
|
158
|
-
name
|
|
159
|
-
lastName
|
|
160
|
-
createdAt
|
|
161
|
-
updatedAt
|
|
162
|
-
}
|
|
163
|
-
}\`,
|
|
164
|
-
variables: {
|
|
165
|
-
id: userID,
|
|
166
|
-
user: {
|
|
167
|
-
lastName: 'Luzquiños',
|
|
168
|
-
name: 'Anthony'
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
expect(result.status).toBe(200)
|
|
174
|
-
expect(updateUserResponse.safeParse(result.data).success).toBe(true)
|
|
175
|
-
})
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
describe('API: deleteUser mutation', () => {
|
|
179
|
-
const deleteUserResponse = z.object({
|
|
180
|
-
data: z.object({
|
|
181
|
-
result: z.string()
|
|
182
|
-
})
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
type DeleteUserDTO = z.infer<typeof deleteUserResponse>
|
|
186
|
-
|
|
187
|
-
it('Should delete the created user', async () => {
|
|
188
|
-
const result = await axios.post<DeleteUserDTO>(\`\${BASE_URL}/graphql\`, {
|
|
189
|
-
query: \`mutation deleteById($id: ${dbIsSQL ? 'Float' : 'String'}!) {
|
|
190
|
-
result: deleteById(id: $id)
|
|
191
|
-
}\`,
|
|
192
|
-
variables: {
|
|
193
|
-
id: userID
|
|
194
|
-
}
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
expect(result.status).toBe(200)
|
|
198
|
-
expect(deleteUserResponse.safeParse(result.data).success).toBe(true)
|
|
199
|
-
})
|
|
200
|
-
})
|
|
201
|
-
})
|
|
202
|
-
|
|
203
|
-
afterAll(async () => {
|
|
204
|
-
await Server.stop()
|
|
205
|
-
})
|
|
206
|
-
})\n`
|
|
207
|
-
: `import axios from 'axios'
|
|
208
|
-
import z from 'zod'
|
|
209
|
-
|
|
210
|
-
import { Server } from '../src/network'
|
|
211
|
-
import { userDto } from '../src/schemas'
|
|
212
|
-
|
|
213
|
-
const BASE_URL = \`http://localhost:\${process.env.PORT || 1996}\`
|
|
214
|
-
const baseResponseDto = z.object({
|
|
215
|
-
error: z.boolean(),
|
|
216
|
-
message: z.string()
|
|
217
|
-
})
|
|
218
|
-
|
|
219
|
-
type BaseResponseDTO = z.infer<typeof baseResponseDto>
|
|
220
|
-
|
|
221
|
-
describe('Simba.js tests', () => {
|
|
222
|
-
beforeAll(async () => {
|
|
223
|
-
await Server.start()
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
describe('API endpoints tests', () => {
|
|
227
|
-
let userID = ${dbIsSQL ? 0 : "''"}
|
|
228
|
-
|
|
229
|
-
describe('API: GET /', () => {
|
|
230
|
-
it('Should return 200 with a successful operation', async () => {
|
|
231
|
-
const result = await axios.get<BaseResponseDTO>(BASE_URL)
|
|
232
|
-
|
|
233
|
-
expect(result.status).toBe(200)
|
|
234
|
-
expect(result.data.error).toBe(false)
|
|
235
|
-
expect(baseResponseDto.parse(result.data).error).toBe(false)
|
|
236
|
-
})
|
|
237
|
-
})
|
|
238
|
-
|
|
239
|
-
describe('API: POST /api/users', () => {
|
|
240
|
-
const storeUserResponse = z.object({
|
|
241
|
-
error: z.boolean(),
|
|
242
|
-
message: userDto
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
type StoreUserDTO = z.infer<typeof storeUserResponse>
|
|
246
|
-
|
|
247
|
-
it('Should create a user successfully', async () => {
|
|
248
|
-
const result = await axios.post<StoreUserDTO>(\`\${BASE_URL}/api/users\`, {
|
|
249
|
-
args: {
|
|
250
|
-
lastName: 'Lzq',
|
|
251
|
-
name: 'Anthony'
|
|
252
|
-
}
|
|
253
|
-
})
|
|
254
|
-
|
|
255
|
-
userID = result.data.message.id ?? userID
|
|
256
|
-
expect(userID).toBeTruthy()
|
|
257
|
-
expect(result.status).toBe(201)
|
|
258
|
-
expect(result.data.error).toBe(false)
|
|
259
|
-
expect(storeUserResponse.parse(result.data).error).toBe(false)
|
|
260
|
-
})
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
describe('API: GET /api/user/:id', () => {
|
|
264
|
-
const getOneUserResponse = z.object({
|
|
265
|
-
error: z.boolean(),
|
|
266
|
-
message: userDto
|
|
267
|
-
})
|
|
268
|
-
|
|
269
|
-
type GetOneUserDTO = z.infer<typeof getOneUserResponse>
|
|
270
|
-
|
|
271
|
-
it('Should return a user', async () => {
|
|
272
|
-
const result = await axios.get<GetOneUserDTO>(
|
|
273
|
-
\`\${BASE_URL}/api/user/\${userID}\`
|
|
274
|
-
)
|
|
275
|
-
|
|
276
|
-
expect(result.status).toBe(200)
|
|
277
|
-
expect(result.data.error).toBe(false)
|
|
278
|
-
expect(getOneUserResponse.parse(result.data).error).toBe(false)
|
|
279
|
-
})
|
|
280
|
-
})
|
|
281
|
-
|
|
282
|
-
describe('API: PATCH /api/user/:id', () => {
|
|
283
|
-
const updateUserResponse = z.object({
|
|
284
|
-
error: z.boolean(),
|
|
285
|
-
message: userDto
|
|
286
|
-
})
|
|
287
|
-
|
|
288
|
-
type UpdateUserDTO = z.infer<typeof updateUserResponse>
|
|
289
|
-
|
|
290
|
-
it('Should update a user successfully', async () => {
|
|
291
|
-
const result = await axios.patch<UpdateUserDTO>(
|
|
292
|
-
\`\${BASE_URL}/api/user/\${userID}\`,
|
|
293
|
-
{
|
|
294
|
-
args: {
|
|
295
|
-
lastName: 'Luzquiños',
|
|
296
|
-
name: 'Anthony'
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
)
|
|
300
|
-
|
|
301
|
-
expect(result.status).toBe(200)
|
|
302
|
-
expect(result.data.error).toBe(false)
|
|
303
|
-
expect(updateUserResponse.parse(result.data).error).toBe(false)
|
|
304
|
-
})
|
|
305
|
-
})
|
|
306
|
-
|
|
307
|
-
describe('API: DELETE /api/user/:id', () => {
|
|
308
|
-
it('Should delete the created user', async () => {
|
|
309
|
-
const result = await axios.delete<BaseResponseDTO>(
|
|
310
|
-
\`\${BASE_URL}/api/user/\${userID}\`
|
|
311
|
-
)
|
|
312
|
-
|
|
313
|
-
expect(result.status).toBe(200)
|
|
314
|
-
expect(result.data.error).toBe(false)
|
|
315
|
-
expect(baseResponseDto.parse(result.data).error).toBe(false)
|
|
316
|
-
})
|
|
317
|
-
})
|
|
318
|
-
})
|
|
319
|
-
|
|
320
|
-
afterAll(async () => {
|
|
321
|
-
await Server.stop()
|
|
322
|
-
})
|
|
323
|
-
})\n`,
|
|
324
|
-
file: `${projectName}/test/index.test.ts`
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
13
|
+
module.exports = async ({ projectName, graphql, dbIsSQL, entityContext }) => {
|
|
14
|
+
await mkdirs(`${projectName}/test`)
|
|
328
15
|
|
|
329
16
|
await Promise.all([
|
|
330
|
-
writeFile(
|
|
331
|
-
|
|
17
|
+
writeFile(
|
|
18
|
+
`${projectName}/vitest.config.ts`,
|
|
19
|
+
renderTemplate('config/vitest.config.ts.ejs', { graphql })
|
|
20
|
+
),
|
|
21
|
+
writeFile(
|
|
22
|
+
`${projectName}/test/index.test.ts`,
|
|
23
|
+
renderTemplate('config/test/index.test.ts.ejs', {
|
|
24
|
+
graphql,
|
|
25
|
+
dbIsSQL,
|
|
26
|
+
...entityContext
|
|
27
|
+
})
|
|
28
|
+
)
|
|
332
29
|
])
|
|
333
30
|
}
|