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

[GitHub Actions] Set up GitHub Actions to automatically build, test, and format #23

Merged
merged 23 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6e078f5
ci(GH Actions): Initial basic build & test
WeirdAlex03 Oct 12, 2022
ab6cf9e
ci(GH Actions): Remove Node v14 from tests
WeirdAlex03 Oct 12, 2022
e1445e1
ci(GH Actions): Disable fail-fast, new format run
WeirdAlex03 Oct 12, 2022
9220a68
ci(GH Actions): Fix format run
WeirdAlex03 Oct 12, 2022
43fcf4b
ci(GH Actions): Add Docker setup to build and test
WeirdAlex03 Oct 12, 2022
cb5c42a
ci(GH Actions): Edit docker run command
WeirdAlex03 Oct 12, 2022
0f47927
ci(GH Actions): Separate test, add annotations
WeirdAlex03 Oct 13, 2022
02d5519
ci(GH Actions): Fix test action
WeirdAlex03 Oct 13, 2022
e675f11
ci(GH Actions): Restructure actions into one file
WeirdAlex03 Oct 14, 2022
a2624cf
ci(GH Actions): Fix actions again
WeirdAlex03 Oct 14, 2022
16e4c42
ci(GH Actions): Clean up action runs
WeirdAlex03 Oct 14, 2022
ddc6ce6
test(GH Actions): Ex. of failing test, formatting
WeirdAlex03 Oct 14, 2022
46c88c0
ci(GH Actions): Formatter needs to commit results
WeirdAlex03 Oct 19, 2022
3e7a255
ci(GH Actions): Looks good, actually committing
WeirdAlex03 Oct 19, 2022
5412e59
ci(GH Actions): Try different method to commit
WeirdAlex03 Oct 19, 2022
c2e2b25
Merge 5412e59a36bb1685e7bb51ee5d906e6b55cafdf5 into b4200ef1bd89f3e84…
WeirdAlex03 Oct 19, 2022
2f80b8a
style: run formatter
WeirdAlex03 Oct 19, 2022
a2f07be
ci(GH Actions): Different commit technique
WeirdAlex03 Oct 19, 2022
0c35121
ci(GH Actions): Fix checkout to work with commit
WeirdAlex03 Oct 19, 2022
bec0ff1
style: run formatter
github-actions[bot] Oct 19, 2022
c84da63
test(GH Actions): It works, undo broken test
WeirdAlex03 Oct 19, 2022
66084d4
ci(GH Actions): Formatter needs to commit results
WeirdAlex03 Oct 19, 2022
20e571a
Merge branch 'master' into issue22
WeirdAlex03 Oct 19, 2022
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
85 changes: 85 additions & 0 deletions .github/workflows/pr-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: PR Review

on: [ pull_request, workflow_dispatch ]

jobs:
build:
name: Build

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Prepare environment
run: |
docker run --name typeorm-postgres -p 5432:5432 -e POSTGRES_PASSWORD=password -e POSTGRES_DB=typescript_api -e POSTGRES_USER=typescript_user -d postgres
npm ci
npm run generate-config
npm run typeorm -- migration:run
- name: Build project
run: npm run build


test:
name: Run tests

needs: build

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
cache: 'npm'
- name: Prepare environment
run: |
docker run --name typeorm-postgres -p 5432:5432 -e POSTGRES_PASSWORD=password -e POSTGRES_DB=typescript_api -e POSTGRES_USER=typescript_user -d postgres
npm ci
npm run generate-config
npm run typeorm -- migration:run
- name: Build project
run: npm run build
- name: Run tests
uses: mattallty/jest-github-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


format:
name: Run formatter

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Use Node.js
uses: actions/setup-node@v3
with:
cache: 'npm'
- name: Prepare environment
run: npm ci
- name: Run formatter
run: npm run format
- name: Commit results
uses: EndBug/add-and-commit@v9
with:
message: 'style: run formatter'
default_author: github_actions
126 changes: 62 additions & 64 deletions docs/SCHEMA.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,109 +13,107 @@
- [ ] [Category](#category)
- [ ] [CourseScore](#coursescore)



# Entity Details

### Generic Entity Attributes
* id
* createdAt
* updatedAt
* deletedAt

- id
- createdAt
- updatedAt
- deletedAt

### User
*Student user for devu*
* email: string
* externalId: foreign_key
* preferredName: string

_Student user for devu_

- email: string
- externalId: foreign_key
- preferredName: string

### Course
* name: string
* semester: string
* number: string *ex: cse220*
* startDate: ?
* endDate: ?

- name: string
- semester: string
- number: string _ex: cse220_
- startDate: ?
- endDate: ?

### UserCourse
*Links a user to a course*
* userId: foreign_key
* courseId: foreign_key
* level: ?
* dropped: boolean

_Links a user to a course_

- userId: foreign_key
- courseId: foreign_key
- level: ?
- dropped: boolean

### Assignment
* courseId: foreign_key
* name: string
* startDate: ?
* dueDate: ?
* endDate: ?
* gradingType: ?
* categoryName: ?
* description: string
* maxFileSize: ?
* maxSubmissions: ?
* disableHandins: boolean

- courseId: foreign_key
- name: string
- startDate: ?
- dueDate: ?
- endDate: ?
- gradingType: ?
- categoryName: ?
- description: string
- maxFileSize: ?
- maxSubmissions: ?
- disableHandins: boolean

### Submission
* courseId: foreign_key
* assignmentId: foreign_key
* userId: foreign_key
* content: ?
* type: ?
* submitterIp: ?
* submittedBy: ?
* orignalSubmissionId: ?

- courseId: foreign_key
- assignmentId: foreign_key
- userId: foreign_key
- content: ?
- type: ?
- submitterIp: ?
- submittedBy: ?
- orignalSubmissionId: ?

### AssignmentProblem
* assignmentId: foreign_key
* problemName: ?
* maxScore: ?

- assignmentId: foreign_key
- problemName: ?
- maxScore: ?

**------ Everything above this line exists in the code. Everything below needs to be built ------**


### SubmissionProblemScore
* submissionId: foreign_key
* assignmentProblemId: foreign_key
* score: ?
* feedback: ?
* released: ?

- submissionId: foreign_key
- assignmentProblemId: foreign_key
- score: ?
- feedback: ?
- released: ?

### SubmissionScore
* submissionId: foreign_key
* score: ?
* feedback: ?
* released: ?

- submissionId: foreign_key
- score: ?
- feedback: ?
- released: ?

### AssignmentScore
* assignmentId: foreign_key
* userId: foreign_key
* score: ?

- assignmentId: foreign_key
- userId: foreign_key
- score: ?

### CategoryScore
* categoryId: foreign_key
* userId: foreign_key
* *missing attributes*

- categoryId: foreign_key
- userId: foreign_key
- _missing attributes_

### Category
* courseId: foreign_key
* *missing attributes*

- courseId: foreign_key
- _missing attributes_

### CourseScore
* courseId: foreign_key
* userId: foreign_key
* *missing attributes*


- courseId: foreign_key
- userId: foreign_key
- _missing attributes_
7 changes: 3 additions & 4 deletions docs/localAuth.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ If you wish to better understand how this works, here's a bit more information.

When developer auth is enabled, users can provide the email & externalId of the user they wish to login as (or create) and recieve a valid refresh/ access token.


### Fetching the bearer token

Request: `POST /login/developer`

Sample Request body:

```
{
"email": "[email protected]",
Expand All @@ -36,14 +36,15 @@ Sample Response:
```

Sample Response Headers:

```
{
"Set-Cookie": "refreshToken=<token>;<cookie settings>"
}
```

### Using the Bearer token

Request: `GET /users`

Request headers (notice the space between `Bearer` and `<token>`!):
Expand All @@ -56,8 +57,6 @@ Request headers (notice the space between `Bearer` and `<token>`!):

With this flag on, it enabled the `/login/developer` route (see `./router/login.router.ts` for more details).



## Testing SAML Authentication Locally

To test SAML authentication, you will need to configure an Identity Provider (IDP) for the API to authenticate against. As we don't expect anyone to just have a configured IDP laying around ready to go, this will walk through using [SamlTest.id](https://samltest.id/).
Expand Down
4 changes: 3 additions & 1 deletion docs/postman-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

[JSON configuration file for Postman](https://www.getpostman.com/collections/b817928ddd3489a9f8a4)

Postman is a great tool for testing API endpoints. The link above is a configuration file that
Postman is a great tool for testing API endpoints. The link above is a configuration file that
will help setup the basic configuration for working with most of the basic endpoints.

### Get Started

1. Install/Open Postman
2. Copy JSON configuration file link
3. Select `Import > Link`
4. Paste the link, click continue, and then click `Import`

### Setup Auth

See `docs/localAuth.md` for examples

1. Using the auth folder, run `retrieve auth token`
Expand Down
4 changes: 2 additions & 2 deletions src/controller/tests/userCourses.controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ describe('UserCourseController', () => {
UserCourseService.list = jest.fn().mockImplementation(() => Promise.resolve(mockedUserCourses))
await controller.get(req, res, next) // what we're testing
})
test('UserId is passed to UserCourseService',() => expect(UserCourseService.list).toBeCalledWith(expectedUserId))

test('UserId is passed to UserCourseService', () => expect(UserCourseService.list).toBeCalledWith(expectedUserId))
test('Returns list of userCourses', () => expect(res.json).toBeCalledWith(expectedResults))
test('Status code is 200', () => expect(res.status).toBeCalledWith(200))
})
Expand Down
2 changes: 1 addition & 1 deletion src/controller/userCourses.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { GenericResponse, NotFound, Updated } from '../utils/apiResponse.utils'
export async function get(req: Request, res: Response, next: NextFunction) {
try {
if (!req.currentUser?.userId) return res.status(400).json(new GenericResponse('Request requires auth'))

const userCourses = await UserCourseService.list(req.currentUser.userId)

res.status(200).json(userCourses.map(serialize))
Expand Down