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(generate): basic zine structure #5

Merged
merged 62 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
8485c21
Template stuff
superflyxxi Oct 29, 2021
e178fbb
Copied template
superflyxxi Oct 29, 2021
b411676
init
superflyxxi Oct 29, 2021
c615483
Copy
superflyxxi Oct 30, 2021
33e5459
Remove validate
superflyxxi Oct 30, 2021
8504de4
Provide rankRules
superflyxxi Oct 30, 2021
31cc80e
Actual function
superflyxxi Oct 30, 2021
5cc224f
Remove cache dependency
superflyxxi Oct 30, 2021
ff2b736
Use versions
superflyxxi Oct 30, 2021
2536a76
Basic controller
superflyxxi Oct 30, 2021
aa1705c
Basic rank-score test
superflyxxi Oct 30, 2021
d0016a5
Add tests
superflyxxi Oct 30, 2021
7dfba43
Test empty items
superflyxxi Oct 30, 2021
6ace394
Update package json
superflyxxi Oct 30, 2021
833ca72
Args for testing
superflyxxi Oct 30, 2021
441afcb
Ignore test results
superflyxxi Oct 30, 2021
2a8af3f
Fixed formatting
superflyxxi Oct 30, 2021
aa33b79
Test no rankRules
superflyxxi Oct 30, 2021
536991a
Common libraries
superflyxxi Oct 30, 2021
5f2b6ff
Error handler
superflyxxi Oct 30, 2021
c224fbb
common files
superflyxxi Oct 30, 2021
8dc957a
Include assert
superflyxxi Oct 30, 2021
e487664
Merged origin/main
superflyxxi Oct 31, 2021
b44606d
Fixed XO
superflyxxi Oct 31, 2021
28d9e61
Fixed etst-results name
superflyxxi Oct 31, 2021
1f83c67
Moved validation error to common
superflyxxi Oct 31, 2021
28b5683
Validate function
superflyxxi Oct 31, 2021
b470094
Use common
superflyxxi Oct 31, 2021
101dcbb
Fixed xo
superflyxxi Oct 31, 2021
04a670a
Moved validate.js to common
superflyxxi Oct 31, 2021
3a2b354
Tested some basic things
superflyxxi Oct 31, 2021
3bf05ce
Test boolean
superflyxxi Oct 31, 2021
8e26295
Test all Booleans
superflyxxi Oct 31, 2021
43ab56a
Added integers
superflyxxi Oct 31, 2021
940b798
Decimal
superflyxxi Oct 31, 2021
e629eb2
Boolean type
superflyxxi Oct 31, 2021
2fefdbe
Validated arrays
superflyxxi Oct 31, 2021
5e5c8d3
Version Object
superflyxxi Oct 31, 2021
544e210
TEst version
superflyxxi Oct 31, 2021
f8df1bc
Replaced with common
superflyxxi Oct 31, 2021
8523281
Make it incomplete
superflyxxi Oct 31, 2021
a3f208d
Fixed XO
superflyxxi Oct 31, 2021
aa941e9
Validate int-test Dockerfile
superflyxxi Oct 31, 2021
c90f7c1
test empty rank
superflyxxi Oct 31, 2021
4f41543
Test single object
superflyxxi Oct 31, 2021
17eb872
Place identifier in output
superflyxxi Oct 31, 2021
c7473b1
Support providing an identifier field
superflyxxi Nov 1, 2021
91bc893
Test numbers prefer lower
superflyxxi Nov 1, 2021
380b7b2
Test for version
superflyxxi Nov 1, 2021
c5e391d
Finish testing
superflyxxi Nov 1, 2021
6d80f92
sonar scan
superflyxxi Nov 2, 2021
7c0ced8
Renamed to match service
superflyxxi Nov 2, 2021
fbf2d6e
Fixed imports
superflyxxi Nov 2, 2021
94a58e8
Dummy code for now
superflyxxi Nov 2, 2021
77d1e85
Renamed file
superflyxxi Nov 2, 2021
49d6fd3
Basic routing
superflyxxi Nov 2, 2021
08283b9
make it simpler
superflyxxi Nov 2, 2021
f3a6df2
Fixed path
superflyxxi Nov 2, 2021
00e56fd
Fixed correct order of error handling
superflyxxi Nov 2, 2021
80386a2
Renamed to apiDocs
superflyxxi Nov 2, 2021
19bbc8e
Renamed to match file
superflyxxi Nov 2, 2021
b8de3ae
Renamed
superflyxxi Nov 2, 2021
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
5 changes: 2 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ jobs:
working_directory: ./<< parameters.project >>
environment:
MOCHA_FILE: ./test-results.xml
MOCHA_ARGS: --forbid-pending --forbid-only --reporter mocha-junit-reporter
command: |
cp -v ../.c8rc.json ../.mocharc.json ./
npm test
npm test -- --forbid-pending --forbid-only --reporter mocha-junit-reporter
- run:
name: Tar coverage
command: tar -vcf << parameters.project >>-coverage.tar << parameters.project >>/coverage/
Expand Down Expand Up @@ -337,7 +336,7 @@ workflows:
- docker/hadolint:
name: validate-dockerfiles
context: default
dockerfiles: "common/Dockerfile:zine-generator/Dockerfile:template/Dockerfile"
dockerfiles: "common/Dockerfile:int-test/Dockerfile:template/Dockerfile:zine-generator/Dockerfile"
- build-docker:
context: default
project: common
Expand Down
34 changes: 12 additions & 22 deletions common/package-lock.json

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

3 changes: 2 additions & 1 deletion common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"mocha-junit-reporter": "^2.0.2"
},
"dependencies": {
"uuid": "^8.3.2"
"uuid": "^8.3.2",
"validate.js": "^0.13.1"
}
}
27 changes: 26 additions & 1 deletion common/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import process from 'node:process';
import validatejs from 'validate.js';
import {v4 as uuidv4} from 'uuid';

export function errorHandler(error, req, res, next) {
Expand Down Expand Up @@ -41,4 +42,28 @@ export class RouteNotFoundError extends NotFoundError {
}
}

// Export default {errorHandler, RootError, NotFoundError, RouteNotFoundError};
export class ValidationError extends RootError {
constructor(result) {
super('/errors/VALIDATION_ERROR', 'Validation Error', 400, result);
}
}

export function validate(object, constraints) {
const result = validatejs(object, constraints);
if (result) {
throw new ValidationError(result);
}
}

export function getVersionObject(string) {
if (string) {
const splt = string.split('.');
return {
major: splt[0] ? Number.parseInt(splt[0], 10) : undefined,
minor: splt[1] ? Number.parseInt(splt[1], 10) : undefined,
patch: splt[2] ? Number.parseInt(splt[2], 10) : undefined,
};
}

return {};
}
249 changes: 249 additions & 0 deletions common/test/validation-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
import chai from 'chai';
import {validate, ValidationError} from '../src/index.js';

const {expect} = chai;

const everything = {s: 'a', b: true, i: 1, d: 1.1, a: [1, 2, 3], o: {name: 'Object'}};

describe('Basic Validation', function () {
it('Empty rules', function () {
validate(everything, {});
});

it('More attributes than expected', function () {
validate(everything, {
z: {presence: false, type: 'string'},
});
});

it('Required attributes', function () {
validate(everything, {
s: {presence: true},
});
});

describe('Sting Validations', function () {
it('String', function () {
expect(function () {
validate(everything, {
s: {presence: false, type: 'string'},
});
}).to.not.throw(ValidationError);
});
it('Bool', function () {
expect(function () {
validate(everything, {
b: {presence: false, type: 'string'},
});
}).to.throw(ValidationError);
});
it('Integer', function () {
expect(function () {
validate(everything, {
i: {presence: false, type: 'string'},
});
}).to.throw(ValidationError);
});
it('Decimal', function () {
expect(function () {
validate(everything, {
d: {presence: false, type: 'string'},
});
}).to.throw(ValidationError);
});
it('Array', function () {
expect(function () {
validate(everything, {
a: {presence: false, type: 'string'},
});
}).to.throw(ValidationError);
});
it('Object', function () {
expect(function () {
validate(everything, {
o: {presence: false, type: 'string'},
});
}).to.throw(ValidationError);
});
});

describe('Boolean Validations', function () {
it('String', function () {
expect(function () {
validate(everything, {
s: {presence: false, type: 'boolean'},
});
}).to.throw(ValidationError);
});
it('Bool', function () {
expect(function () {
validate(everything, {
b: {presence: false, type: 'boolean'},
});
}).to.not.throw(ValidationError);
});
it('Integer', function () {
expect(function () {
validate(everything, {
i: {presence: false, type: 'boolean'},
});
}).to.throw(ValidationError);
});
it('Decimal', function () {
expect(function () {
validate(everything, {
d: {presence: false, type: 'boolean'},
});
}).to.throw(ValidationError);
});
it('Array', function () {
expect(function () {
validate(everything, {
a: {presence: false, type: 'boolean'},
});
}).to.throw(ValidationError);
});
it('Object', function () {
expect(function () {
validate(everything, {
o: {presence: false, type: 'boolean'},
});
}).to.throw(ValidationError);
});
});

describe('Integer Validations', function () {
it('String', function () {
expect(function () {
validate(everything, {
s: {presence: false, type: 'integer'},
});
}).to.throw(ValidationError);
});
it('Bool', function () {
expect(function () {
validate(everything, {
b: {presence: false, type: 'integer'},
});
}).to.throw(ValidationError);
});
it('Integer', function () {
expect(function () {
validate(everything, {
i: {presence: false, type: 'integer'},
});
}).to.not.throw(ValidationError);
});
it('Decimal', function () {
expect(function () {
validate(everything, {
d: {presence: false, type: 'integer'},
});
}).to.throw(ValidationError);
});
it('Array', function () {
expect(function () {
validate(everything, {
a: {presence: false, type: 'integer'},
});
}).to.throw(ValidationError);
});
it('Object', function () {
expect(function () {
validate(everything, {
o: {presence: false, type: 'integer'},
});
}).to.throw(ValidationError);
});
});

describe('Decimal Validations', function () {
it('String', function () {
expect(function () {
validate(everything, {
s: {presence: false, type: 'number'},
});
}).to.throw(ValidationError);
});
it('Bool', function () {
expect(function () {
validate(everything, {
b: {presence: false, type: 'number'},
});
}).to.throw(ValidationError);
});
it('Integer', function () {
expect(function () {
validate(everything, {
i: {presence: false, type: 'number'},
});
}).to.not.throw(ValidationError);
});
it('Decimal', function () {
expect(function () {
validate(everything, {
d: {presence: false, type: 'number'},
});
}).to.not.throw(ValidationError);
});
it('Array', function () {
expect(function () {
validate(everything, {
a: {presence: false, type: 'number'},
});
}).to.throw(ValidationError);
});
it('Object', function () {
expect(function () {
validate(everything, {
o: {presence: false, type: 'number'},
});
}).to.throw(ValidationError);
});
});

describe('Arrray Validations', function () {
it('String', function () {
expect(function () {
validate(everything, {
s: {presence: false, type: 'array'},
});
}).to.throw(ValidationError);
});
it('Bool', function () {
expect(function () {
validate(everything, {
b: {presence: false, type: 'array'},
});
}).to.throw(ValidationError);
});
it('Integer', function () {
expect(function () {
validate(everything, {
i: {presence: false, type: 'array'},
});
}).to.throw(ValidationError);
});
it('Decimal', function () {
expect(function () {
validate(everything, {
d: {presence: false, type: 'array'},
});
}).to.throw(ValidationError);
});
it('Array', function () {
expect(function () {
validate(everything, {
a: {presence: false, type: 'array'},
});
}).to.not.throw(ValidationError);
});
it('Object', function () {
expect(function () {
validate(everything, {
o: {presence: false, type: 'array'},
});
}).to.throw(ValidationError);
});
});
});
Loading