From 84da6ee3448f2bfd6f71402a57e3c06c1d8717c8 Mon Sep 17 00:00:00 2001 From: Benjamin Klein Date: Tue, 21 May 2019 11:17:30 +0200 Subject: [PATCH] Feature: Non Integer IDs (#91) * Stuff * Fixes * Add check script * check -> test:full * Fix tests --- package.json | 10 ++++++- test/integration/plugin.spec.ts | 2 +- .../relations/has-many-through.spec.ts | 16 ++--------- .../relations/many-to-many.spec.ts | 15 ++++++++-- test/support/mock-data.ts | 16 ++++------- test/support/mock-schema.ts | 28 +++++++++---------- test/unit/transformer.spec.ts | 28 +++++++++---------- 7 files changed, 59 insertions(+), 56 deletions(-) diff --git a/package.json b/package.json index c6496cb2..2eed5265 100644 --- a/package.json +++ b/package.json @@ -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", @@ -149,7 +150,14 @@ ], "collectCoverageFrom": [ "src/**/*.{js,ts}" - ] + ], + "globals": { + "ts-jest": { + "diagnostics": { + "ignoreCodes": [2339, 2576] + } + } + } }, "commitlint": { "extends": [ diff --git a/test/integration/plugin.spec.ts b/test/integration/plugin.spec.ts index 04fba236..7aaf4808 100644 --- a/test/integration/plugin.spec.ts +++ b/test/integration/plugin.spec.ts @@ -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(); }); diff --git a/test/integration/relations/has-many-through.spec.ts b/test/integration/relations/has-many-through.spec.ts index e1b0aab5..2e78fb62 100644 --- a/test/integration/relations/has-many-through.spec.ts +++ b/test/integration/relations/has-many-through.spec.ts @@ -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; @@ -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 }); }); diff --git a/test/integration/relations/many-to-many.spec.ts b/test/integration/relations/many-to-many.spec.ts index d0fa357c..32b1ba5f 100644 --- a/test/integration/relations/many-to-many.spec.ts +++ b/test/integration/relations/many-to-many.spec.ts @@ -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; @@ -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"); }); }); diff --git a/test/support/mock-data.ts b/test/support/mock-data.ts index 61b3d6b8..a843358e 100644 --- a/test/support/mock-data.ts +++ b/test/support/mock-data.ts @@ -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) }; } @@ -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") }; } } @@ -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") }; } } diff --git a/test/support/mock-schema.ts b/test/support/mock-schema.ts index dc9c989d..02997d05 100644 --- a/test/support/mock-schema.ts +++ b/test/support/mock-schema.ts @@ -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! @@ -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! @@ -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! @@ -282,7 +282,7 @@ export const typeDefs = ` type Tariff { - id: ID + uuid: String name: String! displayName: String tariffType: String @@ -292,7 +292,7 @@ export const typeDefs = ` input TariffFilter { - id: ID + uuid: String name: String displayName: String tariffType: String @@ -301,7 +301,7 @@ export const typeDefs = ` input TariffInput { - id: ID + uuid: String name: String displayName: String tariffType: String @@ -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 } @@ -526,7 +526,7 @@ const comments = [ const tariffs = [ { - id: 1, + uuid: "ED5F2379-6A8B-4E1D-A4E3-A2C03057C2FC", name: "Super DSL S", displayName: "super-dsl-s", tariffType: "dsl", @@ -534,7 +534,7 @@ const tariffs = [ }, { - id: 2, + uuid: "0D32575B-B15A-4949-95A0-73E6BDD75F8F", name: "Super DSL M", displayName: "super-dsl-m", tariffType: "dsl", @@ -542,7 +542,7 @@ const tariffs = [ }, { - id: 3, + uuid: "8E54BEB8-05F3-48A7-A917-405A13865B89", name: "Super DSL L", displayName: "super-dsl-l", tariffType: "dsl", @@ -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(); }; } @@ -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), diff --git a/test/unit/transformer.spec.ts b/test/unit/transformer.spec.ts index a2a42818..0475b471 100644 --- a/test/unit/transformer.spec.ts +++ b/test/unit/transformer.spec.ts @@ -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", @@ -66,7 +66,7 @@ describe("Transformer", () => { } }, { - id: "2", + uuid: "3F8EC67A-314D-413F-996F-87CB9A28A56C", name: "Tariff M", displayName: "Tariff M", slug: "tariff-m", @@ -82,7 +82,7 @@ describe("Transformer", () => { } }, { - id: "3", + uuid: "DDDB5333-DCD7-40AF-A863-DD0E9249155A", name: "Tariff L", displayName: "Tariff L", slug: "tariff-l", @@ -114,7 +114,7 @@ describe("Transformer", () => { } ], displayName: "Tariff S", - id: 1, + uuid: "210306B3-3008-4B91-88E0-8ED1024F5F83", name: "Tariff S", slug: "tariff-s" }, @@ -130,7 +130,7 @@ describe("Transformer", () => { } ], displayName: "Tariff M", - id: 2, + uuid: "3F8EC67A-314D-413F-996F-87CB9A28A56C", name: "Tariff M", slug: "tariff-m" }, @@ -146,7 +146,7 @@ describe("Transformer", () => { } ], displayName: "Tariff L", - id: 3, + uuid: "DDDB5333-DCD7-40AF-A863-DD0E9249155A", name: "Tariff L", slug: "tariff-l" } @@ -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", @@ -254,7 +254,7 @@ describe("Transformer", () => { } ], displayName: "Tariff S", - id: 1, + uuid: "210306B3-3008-4B91-88E0-8ED1024F5F83", name: "Tariff S", slug: "tariff-s" } @@ -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", @@ -296,7 +296,7 @@ describe("Transformer", () => { }, { node: { - id: "2", + uuid: "3F8EC67A-314D-413F-996F-87CB9A28A56C", name: "Tariff M", displayName: "Tariff M", slug: "tariff-m", @@ -316,7 +316,7 @@ describe("Transformer", () => { }, { node: { - id: "3", + uuid: "DDDB5333-DCD7-40AF-A863-DD0E9249155A", name: "Tariff L", displayName: "Tariff L", slug: "tariff-l", @@ -351,7 +351,7 @@ describe("Transformer", () => { } ], displayName: "Tariff S", - id: 1, + uuid: "210306B3-3008-4B91-88E0-8ED1024F5F83", name: "Tariff S", slug: "tariff-s" }, @@ -367,7 +367,7 @@ describe("Transformer", () => { } ], displayName: "Tariff M", - id: 2, + uuid: "3F8EC67A-314D-413F-996F-87CB9A28A56C", name: "Tariff M", slug: "tariff-m" }, @@ -383,7 +383,7 @@ describe("Transformer", () => { } ], displayName: "Tariff L", - id: 3, + uuid: "DDDB5333-DCD7-40AF-A863-DD0E9249155A", name: "Tariff L", slug: "tariff-l" }