Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions .github/workflows/api-client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ jobs:
if: needs.change-detection.outputs.api-client == 'true'
runs-on: ubuntu-latest
steps:
# 1. Checkout the code
- uses: actions/checkout@v2
# 2. Install NPM packages

- name: Install NPM packages
working-directory: ./api-client
run: yarn install

- name: Unit tests
working-directory: ./api-client
run: yarn run test

after-tests:
needs: tests # run after tests
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion api-client/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
coverage
3 changes: 3 additions & 0 deletions api-client/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# API Client

# System requirements
- Node 18.0.0

# Install

1. Install the packages
Expand Down
19 changes: 19 additions & 0 deletions api-client/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type {Config} from '@jest/types';

const config: Config.InitialOptions = {
collectCoverage: true,
collectCoverageFrom: ["./src/**", "./mockData/**", "!./src/routes.json"],
testPathIgnorePatterns: ["./src/routes.json"],
// TODO #88 https://github.com/howToCodeWell/code-quiz/issues/88
// This needs to be un-commented once we reach 90% code coverage
// coverageThreshold: {
// global: {
// lines: 90
// },
// },
verbose: true,
transform: {
"^.+\\.tsx?$": "ts-jest",
},
};
export default config;
2 changes: 1 addition & 1 deletion api-client/mockData/htmlAnswers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const HTMLAnswerTwo: AnswerDTO[] = [
{
id: "3",
content: "8",
is_correct: true,
is_correct: false,
display_order: 3
},
{
Expand Down
11 changes: 8 additions & 3 deletions api-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
"license": "MIT",
"private": false,
"scripts": {
"start": "npx ts-node src/server.ts"
"start": "npx ts-node src/server.ts",
"test": "jest"
},
"devDependencies": {
"@types/jest": "^29.0.3",
"@types/json-server": "^0.14.4",
"jest": "^29.0.3",
"json-server": "^0.17.0",
"@types/json-server": "^0.14.4"
"ts-jest": "^29.0.2"
},
"dependencies": {
"typescript": "^4.8.3"
"typescript": "^4.8.3",
"ts-node": "^10.9.1"
}
}
31 changes: 31 additions & 0 deletions api-client/tests/unit/MockData/htmlAnswers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { HTMLAnswerOne, HTMLAnswerTwo } from '../../../mockData/htmlAnswers'

const countCorrectAnswers = function(options) {
let correctAnswerCount = 0;
options.forEach(function(option){
if(option.is_correct === true) {
correctAnswerCount++;
}
})
return correctAnswerCount
}


describe('HTML Answer One', () => {
it('Should have three possible options', () => {
expect(HTMLAnswerOne.length).toEqual(3)
})

it('Should only have one correct option', () => {
expect(countCorrectAnswers(HTMLAnswerOne)).toEqual(1)
})
})

describe('HTML Answer Two', () => {
it('Should have three possible options', () => {
expect(HTMLAnswerTwo.length).toEqual(4)
})
it('Should only have one correct option', () => {
expect(countCorrectAnswers(HTMLAnswerTwo)).toEqual(1)
})
})
Loading