-
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: implemented tests and gha for express-rest case
- Loading branch information
1 parent
6b6c47f
commit e1f8b32
Showing
13 changed files
with
368 additions
and
558 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Tests - example/express | ||
|
||
on: [push] | ||
|
||
jobs: | ||
test: | ||
name: Testing Simba.js API | ||
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: yarn | ||
|
||
- name: Revert changes into the yarn.lock file | ||
run: git checkout -- yarn.lock | ||
|
||
- name: Run test | ||
run: yarn test:ci | ||
env: | ||
MONGO_URI: ${{ secrets.MONGO_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,55 @@ | ||
import { connect, connection } from 'mongoose' | ||
import { HttpLogger } from 'express-pino-logger' | ||
|
||
const ENVIRONMENTS_WITHOUT_RECONNECTION = ['ci', 'local'] | ||
const dbConnection = async ( | ||
logger: HttpLogger['logger'] | ||
): Promise<{ | ||
connect: () => Promise<typeof import('mongoose')> | ||
disconnect: () => Promise<void> | ||
}> => { | ||
const connectionConfig = { | ||
keepAlive: true, | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true | ||
} | ||
|
||
connection.on('connected', () => { | ||
logger.info('Mongo connection established.') | ||
}) | ||
connection.on('reconnected', () => { | ||
logger.info('Mongo connection reestablished') | ||
}) | ||
connection.on('disconnected', () => { | ||
if ( | ||
!ENVIRONMENTS_WITHOUT_RECONNECTION.includes( | ||
process.env.NODE_ENV as string | ||
) | ||
) { | ||
logger.info( | ||
'Mongo connection disconnected. Trying to reconnected to Mongo...' | ||
) | ||
setTimeout(() => { | ||
connect(process.env.MONGO_URI as string, { | ||
...connection, | ||
connectTimeoutMS: 3000, | ||
socketTimeoutMS: 3000 | ||
}) | ||
}, 3000) | ||
} | ||
}) | ||
connection.on('close', () => { | ||
logger.info('Mongo connection closed') | ||
}) | ||
connection.on('error', (e: Error) => { | ||
logger.info('Mongo connection error:') | ||
logger.error(e) | ||
}) | ||
|
||
return { | ||
connect: () => connect(process.env.MONGO_URI as string, connectionConfig), | ||
disconnect: () => connection.close() | ||
} | ||
} | ||
|
||
export { dbConnection } |
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,2 +1,3 @@ | ||
export * from './models' | ||
export * from './queries' | ||
export * from './connection' |
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
Oops, something went wrong.