-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sequelize integration part 7 - fixed tests and added express bo…
…ilerplate TODO: - test with graphql
- Loading branch information
1 parent
f37356f
commit fae427f
Showing
118 changed files
with
12,621 additions
and
4,575 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Tests for Simba APIs | ||
|
||
on: [push] | ||
|
||
jobs: | ||
test: | ||
environment: Test-postgresql | ||
name: Tests for Simba APIs | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out Git repository | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16.x | ||
|
||
- name: Install Node.js dependencies | ||
run: npm ci | ||
|
||
- name: Revert changes into the package-lock.json file | ||
run: git checkout -- package-lock.json | ||
|
||
- name: Test APIs | ||
run: npm run test:ci | ||
env: | ||
DB_URI: ${{ secrets.DB_URI }} | ||
NODE_ENV: ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
### Testing store a user | ||
POST http://localhost:1996/api/users | ||
Content-Type: application/json | ||
|
||
{ | ||
"args": { | ||
"lastName": "Lzq", | ||
"name": "Anthony" | ||
} | ||
} | ||
|
||
### Testing getAll users | ||
GET http://localhost:1996/api/users | ||
|
||
### Testing deleteAll users | ||
DELETE http://localhost:1996/api/users | ||
|
||
### Testing getOne user | ||
GET http://localhost:1996/api/user/60e7e3b93b01c1a7aa74cd6b | ||
|
||
### Testing update user | ||
PATCH http://localhost:1996/api/user/60e7e3b93b01c1a7aa74cd6b | ||
Content-Type: application/json | ||
|
||
{ | ||
"args": { | ||
"name": "Anthony", | ||
"lastName": "Luzquiños" | ||
} | ||
} | ||
|
||
### Testing delete user | ||
DELETE http://localhost:1996/api/user/60e7e3b93b01c1a7aa74cd6b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './home' | ||
export * from './user' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { NextFunction, Router } from 'express' | ||
|
||
import { response } from 'network/response' | ||
import { UserService } from 'services' | ||
import { idSchema, storeUserDto, UserWithId } from 'schemas' | ||
import { validatorCompiler } from './utils' | ||
|
||
const User = Router() | ||
|
||
User.route('/users') | ||
.post( | ||
validatorCompiler(storeUserDto, 'body'), | ||
async ( | ||
req: CustomRequest, | ||
res: CustomResponse, | ||
next: NextFunction | ||
): Promise<void> => { | ||
try { | ||
const { | ||
body: { args: user } | ||
} = req | ||
const us = new UserService({ user }) | ||
const result = await us.process({ type: 'store' }) | ||
|
||
response({ error: false, message: result, res, status: 201 }) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
) | ||
.get( | ||
async ( | ||
req: CustomRequest, | ||
res: CustomResponse, | ||
next: NextFunction | ||
): Promise<void> => { | ||
try { | ||
const us = new UserService() | ||
const result = await us.process({ type: 'getAll' }) | ||
|
||
response({ error: false, message: result, res, status: 200 }) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
) | ||
.delete( | ||
async ( | ||
req: CustomRequest, | ||
res: CustomResponse, | ||
next: NextFunction | ||
): Promise<void> => { | ||
try { | ||
const us = new UserService() | ||
const result = await us.process({ type: 'deleteAll' }) | ||
|
||
response({ error: false, message: result, res, status: 200 }) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
) | ||
|
||
User.route('/user/:id') | ||
.get( | ||
validatorCompiler(idSchema, 'params'), | ||
async ( | ||
req: CustomRequest, | ||
res: CustomResponse, | ||
next: NextFunction | ||
): Promise<void> => { | ||
try { | ||
const { | ||
params: { id } | ||
} = req | ||
const us = new UserService({ id }) | ||
const result = await us.process({ type: 'getOne' }) | ||
|
||
response({ error: false, message: result, res, status: 200 }) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
) | ||
.patch( | ||
validatorCompiler(idSchema, 'params'), | ||
validatorCompiler(storeUserDto, 'body'), | ||
async ( | ||
req: CustomRequest, | ||
res: CustomResponse, | ||
next: NextFunction | ||
): Promise<void> => { | ||
try { | ||
const { | ||
body: { args }, | ||
params: { id } | ||
} = req | ||
const userWithId = { | ||
id, | ||
...args | ||
} as UserWithId | ||
const us = new UserService({ userWithId }) | ||
const result = await us.process({ type: 'update' }) | ||
|
||
response({ error: false, message: result, res, status: 200 }) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
) | ||
.delete( | ||
validatorCompiler(idSchema, 'params'), | ||
async ( | ||
req: CustomRequest, | ||
res: CustomResponse, | ||
next: NextFunction | ||
): Promise<void> => { | ||
try { | ||
const { | ||
params: { id } | ||
} = req | ||
const us = new UserService({ id }) | ||
const result = await us.process({ type: 'delete' }) | ||
|
||
response({ error: false, message: result, res, status: 200 }) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
) | ||
|
||
export { User } |
Oops, something went wrong.