Skip to content
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

feat: Finish implementing project creation on backend (#21) #38

Merged
merged 6 commits into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
"name": "Launch Chrome (Frontend)",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}"
},
{
"type": "node",
"request": "launch",
"name": "Debug e2e tests",
"program": "${workspaceRoot}/node_modules/.bin/jest",
"args": ["--runInBand", "--config", "./test/jest-e2e.json", "--verbose"],
"console": "integratedTerminal",
"env": {
"NODE_ENV": "test",
"TEST_GITHUB_TOKEN": "Insert your personal access token from GitHub",
"TEST_GITHUB_USER": "Insert your GitHub account name for testing"
},
"sourceMaps": true,
"runtimeArgs": ["-r", "tsconfig-paths/register", "-r", "ts-node/register"]
}
]
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"nestjs",
"prestart"
],
"files.autoSave": "onFocusChange"
"files.autoSave": "onFocusChange",
"debug.node.autoAttach": "off"
}
8 changes: 8 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@
"problemMatcher": [
"$tslint5"
]
},
{
"type": "npm",
"script": "test:e2e:watch",
"problemMatcher": [
"$awesomets-lint"
],
"group": "build"
}
]
}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ In the `*.env` file replace the values for `CLIENT_ID` and `CLIENT_SECRET` with
_Client Secret_ that GitHub displays for the app. You should also replace the value for
`SESSION_SECRET` with a random value.

If you want to run all e2e tests, you'll have to create a test user on GitHub. Fork
[kdotester1/khmer_angkor](https://github.com/kdotester1/khmer_angkor) to your test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should create a repo on @keymanapp with a good 'testing' name such as "test_kdo_khmer_angkor" and use that rather than relying on another repo that may run into maintenance and access issues in the future?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Can you fork kdotester1/test_kdo_khmer_angkor and keymanapptest/test_kdo_keyboards into @keymanapp?

account and set two environment variables before running the e2e tests:

```bash
export TEST_GITHUB_USER=<GitHubTestUser>
export TEST_GITHUB_TOKEN=<PersonalAccessTokenForGitHubTestUser>
```

## Development

```bash
Expand Down
67 changes: 41 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
"start:prod": "cross-env NODE_ENV=production node dist/main.js",
"lint": "tslint -p tsconfig.lint.json -c tslint.json",
"test": "cross-env NODE_ENV=test jest",
"test:watch": "cross-env NODE_ENV=test jest --watch",
"test:watch": "cross-env NODE_ENV=test jest --watch --verbose",
"test:cov": "cross-env NODE_ENV=test jest --coverage",
"test:debug": "cross-env NODE_ENV=test node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "cross-env NODE_ENV=test jest --config ./test/jest-e2e.json"
"test:e2e": "cross-env NODE_ENV=test jest --verbose --config ./test/jest-e2e.json",
"test:e2e:watch": "cross-env NODE_ENV=test jest --verbose --config ./test/jest-e2e.json --watch --onlyChanged",
"test:e2e:debug": "cross-env NODE_ENV=test node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand --config ./test/jest-e2e.json"
},
"dependencies": {
"@hapi/joi": "^16.1.4",
Expand Down Expand Up @@ -58,13 +60,15 @@
"@types/node": "^12.7.5",
"@types/supertest": "^2.0.8",
"axios-mock-adapter": "^1.17.0",
"base-64": "^0.1.0",
"cross-env": "^6.0.0",
"gulp": "^4.0.2",
"gulp-run-command": "0.0.9",
"jest": "^24.9.0",
"nodemon": "^1.19.2",
"prettier": "^1.18.2",
"supertest": "^4.0.2",
"supertest-session": "^4.0.0",
"ts-jest": "^24.1.0",
"ts-mockito": "^2.5.0",
"ts-node": "^8.4.1",
Expand Down
4 changes: 3 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ export class AppModule implements NestModule {

if (process.env.NODE_ENV !== 'test') {
// It seems that MemoryStore has a bug (https://github.com/roccomuso/memorystore/issues/11)
// so that it doesn't properly shut down when unit tests end
// so that it doesn't properly shut down when unit tests end. On the other hand it is safe
// to be used in production.
sessionOpts.store = new MemoryStore({
checkPeriod: 24 * 60 * 60 * 1000, // 24 hrs * 60 min * 60 sec * 1000 ms
});
} else {
cookie.secure = false;
sessionOpts.store = new expressSession.MemoryStore();
}

ExpressSessionMiddleware.configure(sessionOpts);
Expand Down
14 changes: 12 additions & 2 deletions src/auth/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ValidationPipe,
Delete,
Headers,
Param,
} from '@nestjs/common';
import { Observable } from 'rxjs';

Expand Down Expand Up @@ -36,7 +37,7 @@ export class UserController {
): Promise<AccessTokenDto> {
return callWithErrorHandling(
() => this.githubService.getAccessToken(loginDto.code, loginDto.state),
(response) => {
response => {
const ghToken = response.data as GitHubAccessToken;
return new AccessTokenDto(ghToken.access_token);
},
Expand All @@ -56,7 +57,7 @@ export class UserController {
): Promise<GitHubUserDto> {
return callWithErrorHandling(
() => this.githubService.getUserInformation(token),
(response) => {
response => {
const user = response.data as GitHubUser;
session.login = user.login;
return new GitHubUserDto(user);
Expand All @@ -65,4 +66,13 @@ export class UserController {
);
}

// Method used in tests to set the username in the session
@Get('user/test/:username')
public async getUser(
@Session() session: any,
@Headers('authorization') token: string,
@Param() params: any,
): Promise<void> {
session.login = params.username;
}
}
Loading