-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CHE-195 Create BE Test Setup #154
Changes from all commits
43600a3
b50fdb3
323221f
981c9f1
dae3e18
3030e0c
a205685
35ad808
66fac52
9656c3c
ef06399
513fff2
6f8384f
2dd2aaf
c748707
02c7253
40351e2
7d84c2d
e265c37
014c25d
f8aaa8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as profile controller. Lets axe it. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
version: '3' | ||
services: | ||
test: | ||
image: codehammers/ch-dev-dep-v3:latest | ||
container_name: ch-test | ||
ports: | ||
- '3000:3000' | ||
volumes: | ||
- ./:/usr/src/app | ||
- node_modules:/usr/src/app/node_modules | ||
- client_node_modules:/usr/src/app/client/node_modules | ||
depends_on: | ||
- ch-mongo-test | ||
environment: | ||
- JWT_SECRET=${JWT_SECRET} | ||
- MONGO_URI=mongodb://ch-mongo-test:27017/ch-testdb | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_DB=ch-dev-database | ||
- POSTGRES_PASSWORD=ch-dev | ||
# suppress aws sdk v2 deprecation warning | ||
- AWS_SDK_JS_SUPPRESS_MAINTENANCE_MODE_MESSAGE=1; | ||
- TEST_CMD=${TEST_CMD} | ||
- TEST_FILE=${TEST_FILE} | ||
command: npm run ${TEST_CMD} ${TEST_FILE} | ||
|
||
ch-mongo-test: | ||
image: mongo | ||
container_name: ch-mongo-test | ||
ports: | ||
- '27017:27017' | ||
environment: | ||
- MONGO_INITDB_DATABASE=ch-testdb | ||
# mute mongo container logs | ||
command: mongod --quiet --logpath /dev/null | ||
|
||
volumes: | ||
node_modules: | ||
client_node_modules: |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good rename. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
module.exports = { | ||
roots: ['<rootDir>/__tests__'], | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest', | ||
}, | ||
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$', | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
setupFilesAfterEnv: ['<rootDir>/server/test/setup.ts'], | ||
moduleFileExtensions: ['ts', 'js', 'json'], | ||
testPathIgnorePatterns: [ | ||
'<rootDir>/scripts', | ||
'<rootDir>/node_modules', | ||
'<rootDir>/dist', | ||
'<rootDir>/coverage', | ||
'<rootDir>/client', | ||
], | ||
}; |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. derp derp 🤣 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
|
||
RED='\033[1;31m' | ||
YELLOW='\033[1;33m' | ||
GREEN='\033[1;32;1m' | ||
CORNBLUE="\033[1;3;38;5;69m" | ||
NC='\033[0m' # No color | ||
|
||
# Check to see if they passed in which file they want to test | ||
if [ -z $1 ]; then | ||
echo -e "${RED}Test name not found. Please make sure to format the command properly:${NC}" | ||
echo -en '\n' | ||
echo -e "${YELLOW}Correct Syntax:${NC} 'npm run docker-test:solo <file name>' "; | ||
echo -en '\n' | ||
exit | ||
fi | ||
|
||
printf $"${YELLOW}\nAre you running a server or client test? (Enter S for server or C for client) [S/C]${NC}\n" | ||
read -r SC | ||
|
||
while [[ $SC != 'S' && $SC != 's' && $SC != '' && $SC != 'C' && $SC != 'c' && $SC != 'derp' ]]; do | ||
echo -e "${RED}\nCommand not recognized\nPlease choose ${GREEN}S${RED} for server test or ${GREEN}C${RED} for client test (or Ctrl C to cancel)${NC}\n" | ||
printf $"${YELLOW}\nAre you running a server or client test? (Enter S for server or C for client) [S/C]${NC}\n" | ||
read -r SC | ||
done | ||
|
||
if [[ $SC == "S" || $SC == "s" || $SC == "" ]]; then | ||
echo -e "${GREEN}\nGotcha. Looking for test files matching \"$1\" in the server${NC}\n" | ||
TEST_CMD="test" TEST_FILE=$1 docker-compose -f docker-compose-test-solo.yml up --abort-on-container-exit | ||
fi | ||
|
||
if [[ $SC == "C" || $SC == "c" ]]; then | ||
echo -e "${GREEN}\nGotcha. Looking for test files matching \"$1\" in the client${NC}\n" | ||
TEST_CMD="test:client" TEST_FILE=$1 docker-compose -f docker-compose-test-solo.yml up --abort-on-container-exit | ||
fi | ||
|
||
if [[ $SC == "derp" ]]; then | ||
echo -e "${CORNBLUE}\nWhy are you the way you are? ${RED}Goodbye${NC}\n" | ||
exit 1 | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import mongoose from 'mongoose'; | ||
import app from '../app'; | ||
import request from 'supertest'; | ||
import User from '../models/userModel'; | ||
|
||
declare global { | ||
function login(): Promise<string[]>; | ||
} | ||
|
||
const testUserEmail = '[email protected]'; | ||
const testUserPassword = 'jackieTreehorn'; | ||
|
||
beforeAll(async () => { | ||
process.env.JWT_SECRET = 'asdfasdfasdf'; | ||
await mongoose.connect('mongodb://ch-mongo-test:27017/ch-testdb', {}); | ||
}); | ||
|
||
beforeEach(async () => { | ||
const collections = await mongoose.connection.db.collections(); | ||
|
||
for (const collection of collections) { | ||
await collection.deleteMany({}); | ||
} | ||
}); | ||
|
||
afterAll(async () => { | ||
await mongoose.connection.close(); | ||
}); | ||
|
||
global.login = async () => { | ||
await User.create({ | ||
firstName: 'Sean', | ||
lastName: 'Kelly', | ||
email: testUserEmail, | ||
password: testUserPassword, | ||
}); | ||
|
||
const response = await request(app) | ||
.post('/api/users/login') | ||
.send({ | ||
email: testUserEmail, | ||
password: testUserPassword, | ||
}) | ||
.expect(200); | ||
|
||
const cookie = response.get('Set-Cookie') as string[]; | ||
|
||
return cookie; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seantokuzo This file and userController can probably just be deleted at this point. The new ticket suite will encompass any testing that existed here.