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

Memo schema tests #253

Merged
merged 10 commits into from
Dec 6, 2021
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
9 changes: 9 additions & 0 deletions firebase/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,14 @@
// "'${workspaceRoot}/node_modules/mocha/bin/_mocha -r ts-node/register -r tsconfig-paths/register --file \"${workspaceRoot}/test/firebase-rules/setup.ts\" --recursive \"${workspaceRoot}/test/firebase-rules/**/*.spec.ts\" --no-timeouts --exit'"
// ]
// },
{
"name": "Debug test in window",
"type": "node",
"protocol": "inspector",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"stopOnEntry": false,
"args": ["-r", "ts-node/register", "-r", "tsconfig-paths/register", "${workspaceRoot}/${relativeFile}"]
}
]
}
1 change: 1 addition & 0 deletions firebase/package-lock.json

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

1 change: 1 addition & 0 deletions firebase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@types/sinon": "^10.0.x",
"@typescript-eslint/eslint-plugin": "^4.32.x",
"@typescript-eslint/parser": "^4.32.x",
"ajv": "^8.8.2",
"eslint": "^7.32.x",
"eslint-config-prettier": "^8.3.x",
"eslint-plugin-prettier": "^4.0.x",
Expand Down
38 changes: 36 additions & 2 deletions firebase/src/core/data/schemas/entities-schemas/memo.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,46 @@
"id": { "type": "string" },
"question": {
"type": "array",
"items": { "type": "object" },
"items": {
"type": "object",
"properties": {
"insert": { "type": "string" },
"attributes": {
"type": "object",
"minProperties": 1,
"properties": {
"bold": { "type": "boolean" },
"underline": { "type": "boolean" },
"italic": { "type": "boolean" },
"code-block": { "type": "boolean" }
},
"additionalProperties": false
}
},
"required": [ "insert" ]
},
"minItems": 1
},
"answer": {
"type": "array",
"items": { "type": "object" },
"items": {
"type": "object",
"properties": {
"insert": { "type": "string" },
"attributes": {
"type": "object",
"minProperties": 1,
"properties": {
"bold": { "type": "boolean" },
"underline": { "type": "boolean" },
"italic": { "type": "boolean" },
"code-block": { "type": "boolean" }
},
"additionalProperties": false
}
},
"required": [ "insert" ]
},
"minItems": 1
}
},
Expand Down
28 changes: 24 additions & 4 deletions firebase/src/core/domain/models/memo.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
import { defaultMaxStringLength, validate } from "#utils/validate";
import * as Joi from "joi";

interface MemoContent {
insert: string;
attributes?: {
bold?: boolean;
italic?: boolean;
underline?: boolean;
codeBlock?: boolean;
};
}

export interface Memo {
readonly id: string;
readonly question: Record<string, unknown>[];
readonly answer: Record<string, unknown>[];
readonly question: MemoContent[];
readonly answer: MemoContent[];
}

const memoQuillValidationSchema = Joi.object({
insert: Joi.string().max(defaultMaxStringLength).required(),
attributes: Joi.object({
bold: Joi.boolean(),
italic: Joi.boolean(),
underline: Joi.boolean(),
codeBlock: Joi.boolean(),
}).min(1),
});

export const memoValidationSchema = Joi.object({
id: Joi.string().max(defaultMaxStringLength).required(),
question: Joi.array().items(Joi.object()).min(1).required(),
answer: Joi.array().items(Joi.object()).min(1).required(),
question: Joi.array().items(memoQuillValidationSchema).min(1).required(),
answer: Joi.array().items(memoQuillValidationSchema).min(1).required(),
});

export function validateMemo(memo: Memo): void {
Expand Down
85 changes: 4 additions & 81 deletions firebase/src/core/package-lock.json

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

1 change: 0 additions & 1 deletion firebase/src/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"main": "dist/src/core/index.js",
"private": true,
"dependencies": {
"ajv": "^8.6.x",
"firebase-admin": "^9.11.x",
"firebase-functions": "^3.16.x",
"joi": "^17.4.x"
Expand Down
Loading