Skip to content

Commit 8a7aa5a

Browse files
authored
Merge pull request #60 from akbuma/auth-testing
Travis Configuration + Login Testing
2 parents 22880c3 + dc785a7 commit 8a7aa5a

File tree

4 files changed

+68
-5
lines changed

4 files changed

+68
-5
lines changed

.travis.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
language: node_js
22
node_js:
3-
- 10
3+
- "10"
4+
dist: trusty
5+
cache:
6+
directories:
7+
- node_modules
8+
install:
9+
- npm install
10+
- npm run prod-build
11+
script:
12+
- npm run test
13+

__tests__/userAuth.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { sessionIsCreated, newUserIsCreated } from '../app/src/helperFunctions/auth';
2+
3+
describe('Login Tests', () => {
4+
jest.setTimeout(10000);
5+
let username;
6+
let password;
7+
8+
// Called under SignIn.tsx
9+
describe('sessionIsCreated', async () => {
10+
it('returns the message \'No Username Input\' when no username is entered', async () => {
11+
username = '';
12+
password = 'codesmith1!'
13+
const result = await sessionIsCreated(username, password).then((loginStatus) => loginStatus);
14+
expect(result).toEqual('No Username Input');
15+
})
16+
17+
it('returns the message \'No Password Input\' when no password is entered', async () => {
18+
username = 'reactyp3test';
19+
password = ''
20+
const result = await sessionIsCreated(username, password).then((loginStatus) => loginStatus);
21+
expect(result).toEqual('No Password Input');
22+
})
23+
24+
it('returns the message \'Invalid Username\' when username does not exist', async () => {
25+
username = 'l!b'; //breaks the 4 character minimum and no special characters
26+
password = 'test';
27+
const result = await sessionIsCreated(username, password).then((loginStatus) => loginStatus);
28+
expect(result).toEqual('Invalid Username');
29+
})
30+
31+
it('returns the message \'Incorrect Password\' when password does not match', async () => {
32+
username = 'reactyp3test';
33+
password = 'incorrect';
34+
const result = await sessionIsCreated(username, password).then((loginStatus) => loginStatus);
35+
expect(result).toEqual('Incorrect Password');
36+
})
37+
38+
it('returns the message \'Success\' when the user passes all auth checks', async () => {
39+
username = 'reactyp3test';
40+
password = 'codesmith1!';
41+
const result = await sessionIsCreated(username, password).then((loginStatus) => loginStatus);
42+
expect(result).toEqual('Success');
43+
})
44+
})
45+
46+
})
47+

app/src/helperFunctions/auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const fetch = require("node-fetch");
2+
13
const isDev = process.env.NODE_ENV === 'development';
24
let serverURL = 'https://reactype.herokuapp.com';
35
if (isDev) {
@@ -33,7 +35,6 @@ export const sessionIsCreated = (
3335
}
3436
})
3537
.catch(err => {
36-
console.log('Error while trying to login', err);
3738
return 'Error';
3839
});
3940
return result;
@@ -69,7 +70,6 @@ export const newUserIsCreated = (
6970
return data; // response is either Email Taken or Username Taken, refer to userController.createUser
7071
})
7172
.catch(err => {
72-
console.log(err);
7373
return 'Error';
7474
});
7575
return result;

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@
7272
"diagnostics": false
7373
}
7474
},
75-
"setupFilesAfterEnv": ["<rootDir>/app/setupTests.ts"],
76-
"snapshotSerializers": ["enzyme-to-json/serializer"]
75+
"setupFilesAfterEnv": [
76+
"<rootDir>/app/setupTests.ts"
77+
],
78+
"snapshotSerializers": [
79+
"enzyme-to-json/serializer"
80+
]
7781
},
7882
"bugs": {
7983
"url": "https://github.com/open-source-labs/ReacType/issues"
@@ -106,6 +110,7 @@
106110
"immutable": "^4.0.0-rc.12",
107111
"js-cookie": "^2.2.1",
108112
"localforage": "^1.7.2",
113+
"node-fetch": "^2.6.0",
109114
"prettier": "^1.19.1",
110115
"prop-types": "^15.6.2",
111116
"react": "^16.13.0",
@@ -123,6 +128,7 @@
123128
"@babel/preset-env": "^7.10.4",
124129
"@babel/preset-react": "^7.10.4",
125130
"@babel/preset-typescript": "^7.10.4",
131+
"@testing-library/react": "^10.4.6",
126132
"@types/chai": "^4.2.11",
127133
"@types/enzyme": "^3.10.5",
128134
"@types/enzyme-adapter-react-16": "^1.0.6",

0 commit comments

Comments
 (0)