mirror of https://github.com/MaxLeiter/Drift
				
				
				
			server: Add first e2e test, github action, health endpoint (#68)
And a bonus health endpoint to make the simplest test possiblepull/70/head
							parent
							
								
									5e9288e9fb
								
							
						
					
					
						commit
						ef005ef0b2
					
				@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					name: Server CI
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					on: push
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					jobs:
 | 
				
			||||||
 | 
					  build:
 | 
				
			||||||
 | 
					    runs-on: ubuntu-latest
 | 
				
			||||||
 | 
					    defaults:
 | 
				
			||||||
 | 
					      run:
 | 
				
			||||||
 | 
					        working-directory: server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    steps:
 | 
				
			||||||
 | 
					      - uses: actions/checkout@v2
 | 
				
			||||||
 | 
					      - name: Setup node
 | 
				
			||||||
 | 
					        uses: actions/setup-node@v1
 | 
				
			||||||
 | 
					        with:
 | 
				
			||||||
 | 
					          node-version: '16'
 | 
				
			||||||
 | 
					      - name: Install deps
 | 
				
			||||||
 | 
					        run: yarn
 | 
				
			||||||
 | 
					      - name: Run tests
 | 
				
			||||||
 | 
					        run: yarn test
 | 
				
			||||||
@ -1 +1,2 @@
 | 
				
			|||||||
node_modules/
 | 
					node_modules/
 | 
				
			||||||
 | 
					__tests__/
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					JWT_SECRET=secret-jwt
 | 
				
			||||||
 | 
					MEMORY_DB=true
 | 
				
			||||||
 | 
					REGISTRATION_PASSWORD=password
 | 
				
			||||||
 | 
					SECRET_KEY=secret
 | 
				
			||||||
@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
 | 
				
			||||||
 | 
					module.exports = {
 | 
				
			||||||
 | 
					  preset: 'ts-jest',
 | 
				
			||||||
 | 
					  testEnvironment: 'node',
 | 
				
			||||||
 | 
					  setupFiles: ["<rootDir>/test/setup-tests.ts"],
 | 
				
			||||||
 | 
					  moduleNameMapper: {
 | 
				
			||||||
 | 
					    "@lib/(.*)": "<rootDir>/src/lib/$1",
 | 
				
			||||||
 | 
					    "@routes/(.*)": "<rootDir>/src/routes/$1"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					import * as request from 'supertest'
 | 
				
			||||||
 | 
					import { app } from '../app'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					describe('GET /health', () => {
 | 
				
			||||||
 | 
					  it('should return 200 and a status up', (done) => {
 | 
				
			||||||
 | 
					    request(app)
 | 
				
			||||||
 | 
					      .get(`/health`)
 | 
				
			||||||
 | 
					      .expect('Content-Type', /json/)
 | 
				
			||||||
 | 
					      .expect(200)
 | 
				
			||||||
 | 
					      .end((err, res) => {
 | 
				
			||||||
 | 
					        if (err) return done(err)
 | 
				
			||||||
 | 
					        expect(res.body).toMatchObject({ 'status': 'UP' })
 | 
				
			||||||
 | 
					        done()
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					import { Router } from "express"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const health = Router()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					health.get("/", async (req, res) => {
 | 
				
			||||||
 | 
						return res.json({
 | 
				
			||||||
 | 
							status: "UP"
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					import * as dotenv from 'dotenv';
 | 
				
			||||||
 | 
					import * as path from 'path';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					dotenv.config({ path: path.resolve(process.cwd(), '.env.test') });
 | 
				
			||||||
											
												
													File diff suppressed because it is too large
													Load Diff
												
											
										
									
								
					Loading…
					
					
				
		Reference in New Issue