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

Feature: Non Integer IDs #91

Merged
merged 5 commits into from
May 21, 2019
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
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"test": "jest",
"test:watch": "jest --watch",
"test:prod": "npm run lint && npm run test -- --coverage --no-cache",
"test:full": "npm lint && npm test && npm build",
"docs:deploy": "npm run build:docs && ./deploy-docs.sh",
"docs:dev": "vuepress dev docs",
"report-coverage": "cat ./coverage/lcov.info | coveralls",
Expand Down Expand Up @@ -149,7 +150,14 @@
],
"collectCoverageFrom": [
"src/**/*.{js,ts}"
]
],
"globals": {
"ts-jest": {
"diagnostics": {
"ignoreCodes": [2339, 2576]
}
}
}
},
"commitlint": {
"extends": [
Expand Down
2 changes: 1 addition & 1 deletion test/integration/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Data } from "../../src/support/interfaces";
let store: any;
let vuexOrmGraphQL;

describe("Plugin GrpahQL", () => {
describe("Plugin GraphQL", () => {
beforeEach(async () => {
[store, vuexOrmGraphQL] = await setupMockData();
});
Expand Down
16 changes: 2 additions & 14 deletions test/integration/relations/has-many-through.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Post, setupMockData, Tariff, User } from "../../support/mock-data";
import { Data } from "../../../src/support/interfaces";
import { setupMockData } from "../../support/mock-data";

let store: any;
let vuexOrmGraphQL;
Expand All @@ -10,17 +9,6 @@ describe("Has Many Through", async () => {
});

test("works", async () => {
// @ts-ignore
await Tariff.fetch();

const tariff: Data = Tariff.query()
.withAllRecursive()
.find(1)! as Data;
expect(tariff.name).toEqual("Super DSL S");
expect(tariff.tariffOptions).not.toEqual(null);
expect(tariff.tariffOptions.length).not.toEqual(0);
expect(tariff.tariffOptions[0].name).toEqual("Installation");
expect(tariff.tariffOptions[0].tariffs).not.toEqual(null);
expect(tariff.tariffOptions[0].tariffs[0].name).toEqual("Super DSL S");
// TODO
});
});
15 changes: 13 additions & 2 deletions test/integration/relations/many-to-many.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setupMockData, User } from "../../support/mock-data";
import { setupMockData, Tariff } from "../../support/mock-data";
import { Data } from "../../../src/support/interfaces";

let store: any;
Expand All @@ -10,6 +10,17 @@ describe("Many To Many Relation", async () => {
});

test("works", async () => {
// FIXME
// @ts-ignore
await Tariff.fetch();

const tariff: Data = Tariff.query()
.withAllRecursive()
.find("ED5F2379-6A8B-4E1D-A4E3-A2C03057C2FC")! as Data;
expect(tariff.name).toEqual("Super DSL S");
expect(tariff.tariffOptions).not.toEqual(null);
expect(tariff.tariffOptions.length).not.toEqual(0);
expect(tariff.tariffOptions[0].name).toEqual("Installation");
expect(tariff.tariffOptions[0].tariffs).not.toEqual(null);
expect(tariff.tariffOptions[0].tariffs[0].name).toEqual("Super DSL S");
});
});
16 changes: 6 additions & 10 deletions test/support/mock-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ export class Comment extends ORMModel {
export class TariffTariffOption extends ORMModel {
static entity = "tariffTariffOptions";

static primaryKey = ["tariffId", "tariffOptionId"];
static primaryKey = ["tariffUuid", "tariffOptionId"];

static fields(): Fields {
return {
tariffId: this.number(0),
tariffUuid: this.string(""),
tariffOptionId: this.number(0)
};
}
Expand All @@ -108,21 +108,17 @@ export class TariffTariffOption extends ORMModel {
export class Tariff extends ORMModel {
static entity = "tariffs";
static eagerLoad = ["tariffOptions"];
static primaryKey = ["uuid"];

static fields(): Fields {
return {
id: this.increment(),
uuid: this.string(""),
name: this.string(""),
displayName: this.string(""),
tariffType: this.string(""),
slug: this.string(""),

tariffOptions: this.belongsToMany(
TariffOption,
TariffTariffOption,
"tariffId",
"tariffOptionId"
)
tariffOptions: this.belongsToMany(TariffOption, TariffTariffOption, "uuid", "tariffOptionId")
};
}
}
Expand All @@ -137,7 +133,7 @@ export class TariffOption extends ORMModel {
name: this.string(""),
description: this.string(""),

tariffs: this.belongsToMany(Tariff, TariffTariffOption, "tariffOptionId", "tariffId")
tariffs: this.belongsToMany(Tariff, TariffTariffOption, "tariffOptionId", "uuid")
};
}
}
Expand Down
28 changes: 14 additions & 14 deletions test/support/mock-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const typeDefs = `
comments(filter: CommentFilter): CommentTypeConnection!
tariffOption(id: ID!): TariffOption!
tariffOptions(filter: TariffOptionFilter): TariffOptionTypeConnection!
tariff(id: ID!): Tariff!
tariff(uuid: String!): Tariff!
tariffs(filter: TariffFilter): TariffTypeConnection!
tariffTariffOption(id: ID!): TariffTariffOption!
tariffTariffOptions(filter: TariffTariffOptionFilter): TariffTariffOptionTypeConnection!
Expand All @@ -46,7 +46,7 @@ export const typeDefs = `
deleteVideo(id: ID!): Video!
deleteComment(id: ID!): Comment!
deleteTariffOption(id: ID!): TariffOption!
deleteTariff(id: ID!): Tariff!
deleteTariff(uuid: String!): Tariff!
createUser(user: UserInput!): User!
createProfile(profile: ProfileInput!): Profile!
Expand All @@ -62,7 +62,7 @@ export const typeDefs = `
updateVideo(id: ID!, video: VideoInput!): Video!
updateComment(id: ID!, comment: CommentInput!): Comment!
updateTariffOption(id: ID!, tariffOption: TariffOptionInput!): TariffOption!
updateTariff(id: ID!, tariff: TariffInput!): Tariff!
updateTariff(uuid: String!, tariff: TariffInput!): Tariff!
upvotePost(captchaToken: String!, id: ID!): Post!
sendSms(to: String!, text: String!): SmsStatus!
Expand Down Expand Up @@ -282,7 +282,7 @@ export const typeDefs = `
type Tariff {
id: ID
uuid: String
name: String!
displayName: String
tariffType: String
Expand All @@ -292,7 +292,7 @@ export const typeDefs = `
input TariffFilter {
id: ID
uuid: String
name: String
displayName: String
tariffType: String
Expand All @@ -301,7 +301,7 @@ export const typeDefs = `
input TariffInput {
id: ID
uuid: String
name: String
displayName: String
tariffType: String
Expand All @@ -315,19 +315,19 @@ export const typeDefs = `
type TariffTariffOption {
tariffId: ID
tariffUuid: String
tariffOptionId: ID
}
input TariffTariffOptionFilter {
tariffId: ID
tariffUuid: String
tariffOptionId: ID
}
input TariffTariffOptionInput {
tariffId: ID
tariffUuid: String
tariffOptionId: ID
}
Expand Down Expand Up @@ -526,23 +526,23 @@ const comments = [

const tariffs = [
{
id: 1,
uuid: "ED5F2379-6A8B-4E1D-A4E3-A2C03057C2FC",
name: "Super DSL S",
displayName: "super-dsl-s",
tariffType: "dsl",
slug: "1as8d8w6iu"
},

{
id: 2,
uuid: "0D32575B-B15A-4949-95A0-73E6BDD75F8F",
name: "Super DSL M",
displayName: "super-dsl-m",
tariffType: "dsl",
slug: "asd8e2c89"
},

{
id: 3,
uuid: "8E54BEB8-05F3-48A7-A917-405A13865B89",
name: "Super DSL L",
displayName: "super-dsl-l",
tariffType: "dsl",
Expand Down Expand Up @@ -786,7 +786,7 @@ function findOne(
filterFn = idOrFn;
} else {
filterFn = (r: any) => {
return parseInt(r.id, 10) === parseInt(idOrFn, 10);
return r.id.toString() === idOrFn.toString();
};
}

Expand All @@ -810,7 +810,7 @@ export const resolvers = {
posts: (parent: any, { filter }: any) => findMany(Post, posts, filter),
comment: (parent: any, { id }: any) => findOne(Comment, comments, id),
comments: (parent: any, { filter }: any) => findMany(Comment, comments, filter),
tariff: (parent: any, { id }: any) => findOne(Tariff, tariffs, id),
tariff: (parent: any, { uuid }: any) => findOne(Tariff, tariffs, uuid),
tariffs: (parent: any, { filter }: any) => findMany(Tariff, tariffs, filter),
tariffOption: (parent: any, { id }: any) => findOne(TariffOption, tariffOptions, id),
tariffOptions: (parent: any, { filter }: any) => findMany(TariffOption, tariffOptions, filter),
Expand Down
28 changes: 14 additions & 14 deletions test/unit/transformer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe("Transformer", () => {
tariffs: {
nodes: [
{
id: "1",
uuid: "210306B3-3008-4B91-88E0-8ED1024F5F83",
name: "Tariff S",
displayName: "Tariff S",
slug: "tariff-s",
Expand All @@ -66,7 +66,7 @@ describe("Transformer", () => {
}
},
{
id: "2",
uuid: "3F8EC67A-314D-413F-996F-87CB9A28A56C",
name: "Tariff M",
displayName: "Tariff M",
slug: "tariff-m",
Expand All @@ -82,7 +82,7 @@ describe("Transformer", () => {
}
},
{
id: "3",
uuid: "DDDB5333-DCD7-40AF-A863-DD0E9249155A",
name: "Tariff L",
displayName: "Tariff L",
slug: "tariff-l",
Expand Down Expand Up @@ -114,7 +114,7 @@ describe("Transformer", () => {
}
],
displayName: "Tariff S",
id: 1,
uuid: "210306B3-3008-4B91-88E0-8ED1024F5F83",
name: "Tariff S",
slug: "tariff-s"
},
Expand All @@ -130,7 +130,7 @@ describe("Transformer", () => {
}
],
displayName: "Tariff M",
id: 2,
uuid: "3F8EC67A-314D-413F-996F-87CB9A28A56C",
name: "Tariff M",
slug: "tariff-m"
},
Expand All @@ -146,7 +146,7 @@ describe("Transformer", () => {
}
],
displayName: "Tariff L",
id: 3,
uuid: "DDDB5333-DCD7-40AF-A863-DD0E9249155A",
name: "Tariff L",
slug: "tariff-l"
}
Expand Down Expand Up @@ -227,7 +227,7 @@ describe("Transformer", () => {
test("transforms incoming data after a mutation into a Vuex-ORM readable structure", () => {
const incomingData = {
createTariff: {
id: "1",
uuid: "210306B3-3008-4B91-88E0-8ED1024F5F83",
name: "Tariff S",
displayName: "Tariff S",
slug: "tariff-s",
Expand All @@ -254,7 +254,7 @@ describe("Transformer", () => {
}
],
displayName: "Tariff S",
id: 1,
uuid: "210306B3-3008-4B91-88E0-8ED1024F5F83",
name: "Tariff S",
slug: "tariff-s"
}
Expand All @@ -276,7 +276,7 @@ describe("Transformer", () => {
edges: [
{
node: {
id: "1",
uuid: "210306B3-3008-4B91-88E0-8ED1024F5F83",
name: "Tariff S",
displayName: "Tariff S",
slug: "tariff-s",
Expand All @@ -296,7 +296,7 @@ describe("Transformer", () => {
},
{
node: {
id: "2",
uuid: "3F8EC67A-314D-413F-996F-87CB9A28A56C",
name: "Tariff M",
displayName: "Tariff M",
slug: "tariff-m",
Expand All @@ -316,7 +316,7 @@ describe("Transformer", () => {
},
{
node: {
id: "3",
uuid: "DDDB5333-DCD7-40AF-A863-DD0E9249155A",
name: "Tariff L",
displayName: "Tariff L",
slug: "tariff-l",
Expand Down Expand Up @@ -351,7 +351,7 @@ describe("Transformer", () => {
}
],
displayName: "Tariff S",
id: 1,
uuid: "210306B3-3008-4B91-88E0-8ED1024F5F83",
name: "Tariff S",
slug: "tariff-s"
},
Expand All @@ -367,7 +367,7 @@ describe("Transformer", () => {
}
],
displayName: "Tariff M",
id: 2,
uuid: "3F8EC67A-314D-413F-996F-87CB9A28A56C",
name: "Tariff M",
slug: "tariff-m"
},
Expand All @@ -383,7 +383,7 @@ describe("Transformer", () => {
}
],
displayName: "Tariff L",
id: 3,
uuid: "DDDB5333-DCD7-40AF-A863-DD0E9249155A",
name: "Tariff L",
slug: "tariff-l"
}
Expand Down