Skip to content

Commit

Permalink
adding if condition
Browse files Browse the repository at this point in the history
  • Loading branch information
kristianmandrup committed Mar 13, 2019
1 parent 4f73407 commit a7c85ec
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./src')
module.exports = require("./src");
11 changes: 11 additions & 0 deletions src/conditions/if-condition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class IfCondition {
constructor(obj) {}

testIf() {}

then() {}

else() {}

get result() {}
}
3 changes: 1 addition & 2 deletions src/create-entry.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { YupSchemaEntry } from "./entry";

function createYupSchemaEntry(opts = {}) {
const { schema, name, key, value, config } = opts;

// const { schema, name, key, value, config } = opts;
return new YupSchemaEntry(opts).toEntry();
}

Expand Down
1 change: 0 additions & 1 deletion src/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class YupSchemaEntry extends Base {
}

defaultType(config) {
console.error({ type: config.type });
// return this.mixed(config)
this.error("toEntry: unknown type", config);
}
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class YupBuilder extends Base {
this.error(`invalid schema: must have a properties object: ${props}`);
return;
}

const name = this.getName(schema);
const properties = this.normalizeRequired(schema);
const shapeConfig = this.propsToShape({ properties, name, config });
Expand Down
10 changes: 7 additions & 3 deletions test/convert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe("yup schema validation", () => {
name
};
const schema = yup.object().shape(shapeConfig);

test("valid json is valid", async () => {
// , age: 24
const valid = await schema.isValid({ name: "jimmy" });
Expand All @@ -26,7 +27,10 @@ describe("name schema", () => {
title: "users",
type: "object",
properties: {
name: { type: "string", required: true }
name: {
type: "string",
required: true
}
}
};

Expand All @@ -39,7 +43,7 @@ describe("name schema", () => {
});

test("converts JSON schema to Yup Schema and validates", async () => {
const json = {
const personSchema = {
$schema: "http://json-schema.org/draft-07/schema#",
$id: "http://example.com/person.schema.json",
title: "Person",
Expand Down Expand Up @@ -68,7 +72,7 @@ test("converts JSON schema to Yup Schema and validates", async () => {
};

const errMessages = {};
const schema = buildYup(json, { errMessages });
const schema = buildYup(personSchema, { errMessages });
// console.dir(schema)
const valid = await schema.isValid({ name: "jimmy", age: 24 });
expect(valid).toBe(true);
Expand Down

0 comments on commit a7c85ec

Please sign in to comment.