Skip to content

Commit

Permalink
Merge pull request #43 from MHMoradian/main
Browse files Browse the repository at this point in the history
tests for schemas are added (plus some minor bugs fixed)
  • Loading branch information
hemedani authored Jan 5, 2024
2 parents 4ae347a + 5529702 commit c34188c
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/acts/setService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ import { Acts, Services } from "./types.ts";
export const setService = (
acts: Services,
serviceName: keyof typeof acts,
service: Acts | string,
) => {
acts[serviceName] = service;
};
service: Acts | string
) => (acts[serviceName] = service);
14 changes: 14 additions & 0 deletions src/models/schema/__tests__/createEmbedded.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { assertEquals } from "https://deno.land/[email protected]/assert/assert_equals.ts";
import { schemaMockData } from "../../mainRelations/__test__/getMainRelations.test.ts";
import { getPureFromMainRelations } from "../getPureFromMainRelations.ts";
import { getPureFromRelatedRelations } from "../getPureFromRelatedRelations.ts";
import { createEmbedded } from "../mod.ts";
import { assertInstanceOf } from "https://deno.land/[email protected]/assert/mod.ts";
import { object } from "../../../npmDeps.ts";

Deno.test({
name: "createEmbedded should return getPureFromMainRelations and getPureFromRelatedRelations from schemaMockData",
fn() {
assertInstanceOf(createEmbedded(schemaMockData, "city"), Object);
},
});
12 changes: 12 additions & 0 deletions src/models/schema/__tests__/createStruct.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { assertEquals } from "https://deno.land/[email protected]/assert/assert_equals.ts";
import { createEmbedded, createStruct, getSchema } from "../mod.ts";
import { schemaMockData } from "../../mainRelations/__test__/getMainRelations.test.ts";
import { assign, object } from "../../../npmDeps.ts";
import { assertInstanceOf } from "https://deno.land/[email protected]/assert/mod.ts";

Deno.test({
name: "getPureSchema should return schema.pure from schemaMockData",
fn() {
assertInstanceOf(createStruct(schemaMockData, "city"), Object);
},
});
39 changes: 39 additions & 0 deletions src/models/schema/__tests__/getFlattenPureFromRelations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { assertInstanceOf } from "https://deno.land/[email protected]/assert/assert_instance_of.ts";
import { schemaMockData } from "../../mainRelations/__test__/getMainRelations.test.ts";
import { getFlattenPureFromRelations } from "../getFlattenPureFromRelations.ts";

Deno.test({
name: "getFlattenPureFromRelations should return flatten pureSchemas from mainRelations when MainRelations is passed",
fn() {
const getOneFlattenPureFromRelations = getFlattenPureFromRelations(
schemaMockData,
"city",
"MainRelations"
);
assertInstanceOf(getOneFlattenPureFromRelations, Object);
},
});

Deno.test({
name: "getFlattenPureFromRelations should return flatten pureSchemas from relatedRelations when RelatedRelations is passed",
fn() {
const getOneFlattenPureFromRelations = getFlattenPureFromRelations(
schemaMockData,
"city",
"RelatedRelations"
);
assertInstanceOf(getOneFlattenPureFromRelations, Object);
},
});

Deno.test({
name: "getFlattenPureFromRelations should return flatten pureSchemas from both relatedRelations and mainRelations when All is passed",
fn() {
const getOneFlattenPureFromRelations = getFlattenPureFromRelations(
schemaMockData,
"city",
"All"
);
assertInstanceOf(getOneFlattenPureFromRelations, Object);
},
});
14 changes: 14 additions & 0 deletions src/models/schema/__tests__/getPureFromMainRelations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { assertInstanceOf } from "https://deno.land/[email protected]/assert/assert_instance_of.ts";
import { schemaMockData } from "../../mainRelations/__test__/getMainRelations.test.ts";
import { getPureFromMainRelations } from "../getPureFromMainRelations.ts";

Deno.test({
name: "getPureFromRelatedRelations should return pureSchemas from relatedRelations",
fn() {
const getOnePureFromMainRelations = getPureFromMainRelations(
schemaMockData,
"city"
);
assertInstanceOf(getOnePureFromMainRelations, Object);
},
});
14 changes: 14 additions & 0 deletions src/models/schema/__tests__/getPureFromRelatedRelations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { assertInstanceOf } from "https://deno.land/[email protected]/assert/assert_instance_of.ts";
import { schemaMockData } from "../../mainRelations/__test__/getMainRelations.test.ts";
import { getPureFromRelatedRelations } from "../mod.ts";

Deno.test({
name: "getPureFromRelatedRelations should return pureSchemas from relatedRelations",
fn() {
const getOnePureFromRelatedRelations = getPureFromRelatedRelations(
schemaMockData,
"city"
);
assertInstanceOf(getOnePureFromRelatedRelations, Object);
},
});
14 changes: 14 additions & 0 deletions src/models/schema/__tests__/getPureOfMainRelations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { assertInstanceOf } from "https://deno.land/[email protected]/assert/assert_instance_of.ts";
import { schemaMockData } from "../../mainRelations/__test__/getMainRelations.test.ts";
import { getPureOfMainRelations } from "../mod.ts";

Deno.test({
name: "getPureOfMainRelations should return pureSchemas and pureInrel",
fn() {
const getOnePureOfMainRelations = getPureOfMainRelations(
schemaMockData,
"city"
);
assertInstanceOf(getOnePureOfMainRelations, Object);
},
});
22 changes: 22 additions & 0 deletions src/models/schema/__tests__/getPureSchema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { assertEquals } from "https://deno.land/[email protected]/assert/assert_equals.ts";
import { schemaMockData } from "../../mainRelations/__test__/getMainRelations.test.ts";
import { getPureSchema } from "../getPureSchema.ts";
import { assertThrows } from "https://deno.land/[email protected]/assert/assert_throws.ts";

Deno.test({
name: "getPureSchema should return schema.pure from schemaMockData",
fn() {
assertEquals(
getPureSchema(schemaMockData, "city"),
schemaMockData.city.pure
);
},
});

Deno.test({
name: "getPureSchema should throw err when schema does not exist",
fn() {
const getNotSchema = () => getPureSchema(schemaMockData, "notCountry");
assertThrows(getNotSchema, Error, "Schema notCountry not found");
},
});
19 changes: 19 additions & 0 deletions src/models/schema/__tests__/getSchema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { assertEquals } from "https://deno.land/[email protected]/assert/assert_equals.ts";
import { schemaMockData } from "../../mainRelations/__test__/getMainRelations.test.ts";
import { getSchema } from "../getSchema.ts";
import { assertThrows } from "https://deno.land/[email protected]/assert/assert_throws.ts";

Deno.test({
name: "getSchema should return schemaMockData from schemaMockData",
fn() {
assertEquals(getSchema(schemaMockData, "country"), schemaMockData.country);
},
});

Deno.test({
name: "getSchema should throw err when schema does not exist",
fn() {
const getNotSchema = () => getSchema(schemaMockData, "notCountry");
assertThrows(getNotSchema, Error, "Schema notCountry not found");
},
});
10 changes: 10 additions & 0 deletions src/models/schema/__tests__/getSchemaKeys.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { assertEquals } from "https://deno.land/[email protected]/assert/assert_equals.ts";
import { schemaMockData } from "../../mainRelations/__test__/getMainRelations.test.ts";
import { getSchemasKeys } from "../getSchemaKeys.ts";

Deno.test({
name: "getSchema should return schemaMockData from schemaMockData",
fn() {
assertEquals(getSchemasKeys(schemaMockData), Object.keys(schemaMockData));
},
});
10 changes: 10 additions & 0 deletions src/models/schema/__tests__/getSchemas.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { assertEquals } from "https://deno.land/[email protected]/assert/assert_equals.ts";
import { getSchemas } from "../getSchemas.ts";
import { schemaMockData } from "../../mainRelations/__test__/getMainRelations.test.ts";

Deno.test({
name: "getSchemas should return schemaMockData from schemaMockData",
fn() {
assertEquals(getSchemas(schemaMockData), schemaMockData);
},
});
8 changes: 4 additions & 4 deletions src/models/schema/getFlattenPureFromRelations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TSchemas } from "./mod.ts";
export const getFlattenPureFromRelations = (
schemas: TSchemas,
schemaName: string,
relationType: "MainRelations" | "RelatedRelations" | "All",
relationType: "MainRelations" | "RelatedRelations" | "All"
) => {
const schema = getSchema(schemas, schemaName);
let pureSchemas = {};
Expand All @@ -15,7 +15,7 @@ export const getFlattenPureFromRelations = (
pureSchemas = {
...pureSchemas,
[property]: object(
schemas[schema.mainRelations[property].schemaName]?.pure,
schemas[schema.mainRelations[property].schemaName]?.pure
),
};
}
Expand All @@ -25,13 +25,13 @@ export const getFlattenPureFromRelations = (
pureSchemas = {
...pureSchemas,
[property]: object(
schemas[schema.relatedRelations[property].schemaName]?.pure,
schemas[schema.relatedRelations[property].schemaName]?.pure
),
};
}
};

if (relationType === "RelatedRelations") {
if (relationType === "MainRelations") {
addMainRelation();
}
if (relationType === "RelatedRelations") {
Expand Down

0 comments on commit c34188c

Please sign in to comment.