Skip to content

Commit

Permalink
Merge branch 'main' into gcs-in-repeat-with-static-cs-repeating-answers
Browse files Browse the repository at this point in the history
  • Loading branch information
katie-gardner authored Dec 14, 2023
2 parents c315927 + 58f5bbd commit c784f05
Show file tree
Hide file tree
Showing 12 changed files with 7,424 additions and 4,292 deletions.
6 changes: 4 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"presets": ["env"]
}
"presets": [
"@babel/preset-env"
]
}
16 changes: 8 additions & 8 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
cache: "yarn"
cache: "npm"
- run: |
echo "PYTHON_VERSION=$(python -c 'import platform; print(platform.python_version())')" >> $GITHUB_ENV
- name: Install yarn deps
run: yarn install
- name: Install npm deps
run: npm install

- name: Install Poetry
uses: snok/install-poetry@v1
Expand Down Expand Up @@ -56,13 +56,13 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
cache: "yarn"
cache: "npm"
- run: |
echo "PYTHON_VERSION=$(python -c 'import platform; print(platform.python_version())')" >> $GITHUB_ENV
- name: Install yarn deps
run: yarn install
- name: Running yarn tests
run: make test-yarn
- name: Install npm deps
run: npm install
- name: Running ajv tests
run: make test-ajv

- name: Install Poetry
uses: snok/install-poetry@v1
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18
v20.10.0
4 changes: 2 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ ignore=CVS
# ignore-list. The regex matches against paths and can be in Posix or Windows
# format. Because '\' represents the directory delimiter on Windows systems, it
# can't be used as an escape character.
ignore-paths=
ignore-paths=node_modules

# Files or directories matching the regular expression patterns are skipped.
# The regex matches against base names, not paths. The default value ignores
Expand Down Expand Up @@ -394,7 +394,7 @@ timeout-methods=requests.api.delete,requests.api.get,requests.api.head,requests.
[EXCEPTIONS]

# Exceptions that will emit a warning when caught.
overgeneral-exceptions=Exception
overgeneral-exceptions=builtins.Exception


[REFACTORING]
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile-ajv
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ WORKDIR /usr/src/app

# Install app dependencies
COPY package.json ./
COPY yarn.lock ./
COPY package-lock.json ./

COPY ajv/app.js .
COPY schemas ../schemas

RUN yarn install --production=true
RUN npm install --production=true

EXPOSE 5002
ENV DEBUG=ajv-schema-validator
Expand Down
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ build:
poetry run ./scripts/build.sh

stop-ajv:
yarn stop
npm run stop

start-ajv:
yarn start
npm run start

run: start-ajv
poetry run ./scripts/run_app.sh

lint: lint-python
yarn lint
npm run lint

lint-python:
poetry run ./scripts/run_lint_python.sh

test-unit:
poetry run ./scripts/run_tests_unit.sh

test-yarn:
yarn test
test-ajv:
npm run test

test: test-unit test-yarn
test: test-unit test-ajv

format: format-python
yarn format
npm run format

format-python:
poetry run isort .
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ To run the app's unit tests:
make test-unit
```

To run the app's unit tests and yarn tests:
To run the app's unit tests and ajv validator tests:

```
make test
Expand All @@ -56,17 +56,16 @@ brew install nvm
nvm install
```

Install yarn and node dependencies:
Install node dependencies:

```
npm i -g yarn
yarn
npm install
```

To run the ajv validator tests:

```
make test-yarn
make test-ajv
```

## Formatting json
Expand Down
70 changes: 35 additions & 35 deletions ajv/app.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import Ajv2020 from "ajv/dist/2020.js";
import fs from "fs";
import glob from "glob";
import { globSync } from "glob";
import express from "express";
import Debug from "debug";

const debug = Debug("ajv-schema-validator");

const app = express();

app.use(
express.json({
limit: "2Mb",
})
);

app.listen(5002, () => {
debug("Server running on port 5002");
});

const ajValidator = new Ajv2020({
allErrors: false,
strict: true,
Expand All @@ -17,44 +26,35 @@ const ajValidator = new Ajv2020({
strictTuples: false, // this has been included due to https://github.com/ajv-validator/ajv/issues/1417
});

app.use(
express.json({
limit: "2Mb",
})
);

app.listen(5002, () => {
debug("Server running on port 5002");
const schemas = globSync("schemas/**/*.json");
schemas.forEach((currentSchema) => {
if (!(currentSchema.valueOf() === "schemas/questionnaire_v1.json")) {
const data = fs.readFileSync(currentSchema); // eslint-disable-line security/detect-non-literal-fs-filename
debug("Adding schema: " + currentSchema);
ajValidator.addSchema(JSON.parse(data)).compile(true);
}
});

// Export our app for testing purposes
export default app;
const baseSchema = fs.readFileSync("schemas/questionnaire_v1.json");
const validate = ajValidator.compile(JSON.parse(baseSchema));

app.get("/status", (req, res, next) => {
return res.sendStatus(200);
});

glob("schemas/**/*.json", (er, schemas) => {
schemas.forEach((currentSchema) => {
if (!(currentSchema.valueOf() === "schemas/questionnaire_v1.json")) {
const data = fs.readFileSync(currentSchema); // eslint-disable-line security/detect-non-literal-fs-filename
ajValidator.addSchema(JSON.parse(data)).compile(true);
}
});
const baseSchema = fs.readFileSync("schemas/questionnaire_v1.json");
const validate = ajValidator.compile(JSON.parse(baseSchema));

app.post("/validate", (req, res, next) => {
debug("Validating questionnaire: " + req.body.title);
const valid = validate(req.body);
if (!valid) {
return res.json({
success: false,
errors: validate.errors.sort((errorA, errorB) => {
return errorA.instancePath.length - errorB.instancePath.length;
}),
});
}
return res.json({});
});
app.post("/validate", (req, res, next) => {
debug("Validating questionnaire: " + req.body.title);
const valid = validate(req.body);
if (!valid) {
return res.json({
success: false,
errors: validate.errors.sort((errorA, errorB) => {
return errorA.instancePath.length - errorB.instancePath.length;
}),
});
}
return res.json({});
});

// Export our app for testing purposes
export default app;
2 changes: 1 addition & 1 deletion ajv/tests/test_questionnaire_validator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Import the dependencies for testing
import chai from "chai";
import chaiHttp from "chai-http";
import app from "../app";
import app from "../app.js";
import fs from "fs";
// Configure chai
chai.use(chaiHttp);
Expand Down
Loading

0 comments on commit c784f05

Please sign in to comment.