Skip to content

Commit 84da6ee

Browse files
authored
Feature: Non Integer IDs (#91)
* Stuff * Fixes * Add check script * check -> test:full * Fix tests
1 parent 9d6654c commit 84da6ee

File tree

7 files changed

+59
-56
lines changed

7 files changed

+59
-56
lines changed

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"test": "jest",
1818
"test:watch": "jest --watch",
1919
"test:prod": "npm run lint && npm run test -- --coverage --no-cache",
20+
"test:full": "npm lint && npm test && npm build",
2021
"docs:deploy": "npm run build:docs && ./deploy-docs.sh",
2122
"docs:dev": "vuepress dev docs",
2223
"report-coverage": "cat ./coverage/lcov.info | coveralls",
@@ -149,7 +150,14 @@
149150
],
150151
"collectCoverageFrom": [
151152
"src/**/*.{js,ts}"
152-
]
153+
],
154+
"globals": {
155+
"ts-jest": {
156+
"diagnostics": {
157+
"ignoreCodes": [2339, 2576]
158+
}
159+
}
160+
}
153161
},
154162
"commitlint": {
155163
"extends": [

test/integration/plugin.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Data } from "../../src/support/interfaces";
66
let store: any;
77
let vuexOrmGraphQL;
88

9-
describe("Plugin GrpahQL", () => {
9+
describe("Plugin GraphQL", () => {
1010
beforeEach(async () => {
1111
[store, vuexOrmGraphQL] = await setupMockData();
1212
});
Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Post, setupMockData, Tariff, User } from "../../support/mock-data";
2-
import { Data } from "../../../src/support/interfaces";
1+
import { setupMockData } from "../../support/mock-data";
32

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

1211
test("works", async () => {
13-
// @ts-ignore
14-
await Tariff.fetch();
15-
16-
const tariff: Data = Tariff.query()
17-
.withAllRecursive()
18-
.find(1)! as Data;
19-
expect(tariff.name).toEqual("Super DSL S");
20-
expect(tariff.tariffOptions).not.toEqual(null);
21-
expect(tariff.tariffOptions.length).not.toEqual(0);
22-
expect(tariff.tariffOptions[0].name).toEqual("Installation");
23-
expect(tariff.tariffOptions[0].tariffs).not.toEqual(null);
24-
expect(tariff.tariffOptions[0].tariffs[0].name).toEqual("Super DSL S");
12+
// TODO
2513
});
2614
});

test/integration/relations/many-to-many.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setupMockData, User } from "../../support/mock-data";
1+
import { setupMockData, Tariff } from "../../support/mock-data";
22
import { Data } from "../../../src/support/interfaces";
33

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

1212
test("works", async () => {
13-
// FIXME
13+
// @ts-ignore
14+
await Tariff.fetch();
15+
16+
const tariff: Data = Tariff.query()
17+
.withAllRecursive()
18+
.find("ED5F2379-6A8B-4E1D-A4E3-A2C03057C2FC")! as Data;
19+
expect(tariff.name).toEqual("Super DSL S");
20+
expect(tariff.tariffOptions).not.toEqual(null);
21+
expect(tariff.tariffOptions.length).not.toEqual(0);
22+
expect(tariff.tariffOptions[0].name).toEqual("Installation");
23+
expect(tariff.tariffOptions[0].tariffs).not.toEqual(null);
24+
expect(tariff.tariffOptions[0].tariffs[0].name).toEqual("Super DSL S");
1425
});
1526
});

test/support/mock-data.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ export class Comment extends ORMModel {
9595
export class TariffTariffOption extends ORMModel {
9696
static entity = "tariffTariffOptions";
9797

98-
static primaryKey = ["tariffId", "tariffOptionId"];
98+
static primaryKey = ["tariffUuid", "tariffOptionId"];
9999

100100
static fields(): Fields {
101101
return {
102-
tariffId: this.number(0),
102+
tariffUuid: this.string(""),
103103
tariffOptionId: this.number(0)
104104
};
105105
}
@@ -108,21 +108,17 @@ export class TariffTariffOption extends ORMModel {
108108
export class Tariff extends ORMModel {
109109
static entity = "tariffs";
110110
static eagerLoad = ["tariffOptions"];
111+
static primaryKey = ["uuid"];
111112

112113
static fields(): Fields {
113114
return {
114-
id: this.increment(),
115+
uuid: this.string(""),
115116
name: this.string(""),
116117
displayName: this.string(""),
117118
tariffType: this.string(""),
118119
slug: this.string(""),
119120

120-
tariffOptions: this.belongsToMany(
121-
TariffOption,
122-
TariffTariffOption,
123-
"tariffId",
124-
"tariffOptionId"
125-
)
121+
tariffOptions: this.belongsToMany(TariffOption, TariffTariffOption, "uuid", "tariffOptionId")
126122
};
127123
}
128124
}
@@ -137,7 +133,7 @@ export class TariffOption extends ORMModel {
137133
name: this.string(""),
138134
description: this.string(""),
139135

140-
tariffs: this.belongsToMany(Tariff, TariffTariffOption, "tariffOptionId", "tariffId")
136+
tariffs: this.belongsToMany(Tariff, TariffTariffOption, "tariffOptionId", "uuid")
141137
};
142138
}
143139
}

test/support/mock-schema.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const typeDefs = `
2626
comments(filter: CommentFilter): CommentTypeConnection!
2727
tariffOption(id: ID!): TariffOption!
2828
tariffOptions(filter: TariffOptionFilter): TariffOptionTypeConnection!
29-
tariff(id: ID!): Tariff!
29+
tariff(uuid: String!): Tariff!
3030
tariffs(filter: TariffFilter): TariffTypeConnection!
3131
tariffTariffOption(id: ID!): TariffTariffOption!
3232
tariffTariffOptions(filter: TariffTariffOptionFilter): TariffTariffOptionTypeConnection!
@@ -46,7 +46,7 @@ export const typeDefs = `
4646
deleteVideo(id: ID!): Video!
4747
deleteComment(id: ID!): Comment!
4848
deleteTariffOption(id: ID!): TariffOption!
49-
deleteTariff(id: ID!): Tariff!
49+
deleteTariff(uuid: String!): Tariff!
5050
5151
createUser(user: UserInput!): User!
5252
createProfile(profile: ProfileInput!): Profile!
@@ -62,7 +62,7 @@ export const typeDefs = `
6262
updateVideo(id: ID!, video: VideoInput!): Video!
6363
updateComment(id: ID!, comment: CommentInput!): Comment!
6464
updateTariffOption(id: ID!, tariffOption: TariffOptionInput!): TariffOption!
65-
updateTariff(id: ID!, tariff: TariffInput!): Tariff!
65+
updateTariff(uuid: String!, tariff: TariffInput!): Tariff!
6666
6767
upvotePost(captchaToken: String!, id: ID!): Post!
6868
sendSms(to: String!, text: String!): SmsStatus!
@@ -282,7 +282,7 @@ export const typeDefs = `
282282
283283
284284
type Tariff {
285-
id: ID
285+
uuid: String
286286
name: String!
287287
displayName: String
288288
tariffType: String
@@ -292,7 +292,7 @@ export const typeDefs = `
292292
293293
294294
input TariffFilter {
295-
id: ID
295+
uuid: String
296296
name: String
297297
displayName: String
298298
tariffType: String
@@ -301,7 +301,7 @@ export const typeDefs = `
301301
302302
303303
input TariffInput {
304-
id: ID
304+
uuid: String
305305
name: String
306306
displayName: String
307307
tariffType: String
@@ -315,19 +315,19 @@ export const typeDefs = `
315315
316316
317317
type TariffTariffOption {
318-
tariffId: ID
318+
tariffUuid: String
319319
tariffOptionId: ID
320320
}
321321
322322
323323
input TariffTariffOptionFilter {
324-
tariffId: ID
324+
tariffUuid: String
325325
tariffOptionId: ID
326326
}
327327
328328
329329
input TariffTariffOptionInput {
330-
tariffId: ID
330+
tariffUuid: String
331331
tariffOptionId: ID
332332
}
333333
@@ -526,23 +526,23 @@ const comments = [
526526

527527
const tariffs = [
528528
{
529-
id: 1,
529+
uuid: "ED5F2379-6A8B-4E1D-A4E3-A2C03057C2FC",
530530
name: "Super DSL S",
531531
displayName: "super-dsl-s",
532532
tariffType: "dsl",
533533
slug: "1as8d8w6iu"
534534
},
535535

536536
{
537-
id: 2,
537+
uuid: "0D32575B-B15A-4949-95A0-73E6BDD75F8F",
538538
name: "Super DSL M",
539539
displayName: "super-dsl-m",
540540
tariffType: "dsl",
541541
slug: "asd8e2c89"
542542
},
543543

544544
{
545-
id: 3,
545+
uuid: "8E54BEB8-05F3-48A7-A917-405A13865B89",
546546
name: "Super DSL L",
547547
displayName: "super-dsl-l",
548548
tariffType: "dsl",
@@ -786,7 +786,7 @@ function findOne(
786786
filterFn = idOrFn;
787787
} else {
788788
filterFn = (r: any) => {
789-
return parseInt(r.id, 10) === parseInt(idOrFn, 10);
789+
return r.id.toString() === idOrFn.toString();
790790
};
791791
}
792792

@@ -810,7 +810,7 @@ export const resolvers = {
810810
posts: (parent: any, { filter }: any) => findMany(Post, posts, filter),
811811
comment: (parent: any, { id }: any) => findOne(Comment, comments, id),
812812
comments: (parent: any, { filter }: any) => findMany(Comment, comments, filter),
813-
tariff: (parent: any, { id }: any) => findOne(Tariff, tariffs, id),
813+
tariff: (parent: any, { uuid }: any) => findOne(Tariff, tariffs, uuid),
814814
tariffs: (parent: any, { filter }: any) => findMany(Tariff, tariffs, filter),
815815
tariffOption: (parent: any, { id }: any) => findOne(TariffOption, tariffOptions, id),
816816
tariffOptions: (parent: any, { filter }: any) => findMany(TariffOption, tariffOptions, filter),

test/unit/transformer.spec.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe("Transformer", () => {
5050
tariffs: {
5151
nodes: [
5252
{
53-
id: "1",
53+
uuid: "210306B3-3008-4B91-88E0-8ED1024F5F83",
5454
name: "Tariff S",
5555
displayName: "Tariff S",
5656
slug: "tariff-s",
@@ -66,7 +66,7 @@ describe("Transformer", () => {
6666
}
6767
},
6868
{
69-
id: "2",
69+
uuid: "3F8EC67A-314D-413F-996F-87CB9A28A56C",
7070
name: "Tariff M",
7171
displayName: "Tariff M",
7272
slug: "tariff-m",
@@ -82,7 +82,7 @@ describe("Transformer", () => {
8282
}
8383
},
8484
{
85-
id: "3",
85+
uuid: "DDDB5333-DCD7-40AF-A863-DD0E9249155A",
8686
name: "Tariff L",
8787
displayName: "Tariff L",
8888
slug: "tariff-l",
@@ -114,7 +114,7 @@ describe("Transformer", () => {
114114
}
115115
],
116116
displayName: "Tariff S",
117-
id: 1,
117+
uuid: "210306B3-3008-4B91-88E0-8ED1024F5F83",
118118
name: "Tariff S",
119119
slug: "tariff-s"
120120
},
@@ -130,7 +130,7 @@ describe("Transformer", () => {
130130
}
131131
],
132132
displayName: "Tariff M",
133-
id: 2,
133+
uuid: "3F8EC67A-314D-413F-996F-87CB9A28A56C",
134134
name: "Tariff M",
135135
slug: "tariff-m"
136136
},
@@ -146,7 +146,7 @@ describe("Transformer", () => {
146146
}
147147
],
148148
displayName: "Tariff L",
149-
id: 3,
149+
uuid: "DDDB5333-DCD7-40AF-A863-DD0E9249155A",
150150
name: "Tariff L",
151151
slug: "tariff-l"
152152
}
@@ -227,7 +227,7 @@ describe("Transformer", () => {
227227
test("transforms incoming data after a mutation into a Vuex-ORM readable structure", () => {
228228
const incomingData = {
229229
createTariff: {
230-
id: "1",
230+
uuid: "210306B3-3008-4B91-88E0-8ED1024F5F83",
231231
name: "Tariff S",
232232
displayName: "Tariff S",
233233
slug: "tariff-s",
@@ -254,7 +254,7 @@ describe("Transformer", () => {
254254
}
255255
],
256256
displayName: "Tariff S",
257-
id: 1,
257+
uuid: "210306B3-3008-4B91-88E0-8ED1024F5F83",
258258
name: "Tariff S",
259259
slug: "tariff-s"
260260
}
@@ -276,7 +276,7 @@ describe("Transformer", () => {
276276
edges: [
277277
{
278278
node: {
279-
id: "1",
279+
uuid: "210306B3-3008-4B91-88E0-8ED1024F5F83",
280280
name: "Tariff S",
281281
displayName: "Tariff S",
282282
slug: "tariff-s",
@@ -296,7 +296,7 @@ describe("Transformer", () => {
296296
},
297297
{
298298
node: {
299-
id: "2",
299+
uuid: "3F8EC67A-314D-413F-996F-87CB9A28A56C",
300300
name: "Tariff M",
301301
displayName: "Tariff M",
302302
slug: "tariff-m",
@@ -316,7 +316,7 @@ describe("Transformer", () => {
316316
},
317317
{
318318
node: {
319-
id: "3",
319+
uuid: "DDDB5333-DCD7-40AF-A863-DD0E9249155A",
320320
name: "Tariff L",
321321
displayName: "Tariff L",
322322
slug: "tariff-l",
@@ -351,7 +351,7 @@ describe("Transformer", () => {
351351
}
352352
],
353353
displayName: "Tariff S",
354-
id: 1,
354+
uuid: "210306B3-3008-4B91-88E0-8ED1024F5F83",
355355
name: "Tariff S",
356356
slug: "tariff-s"
357357
},
@@ -367,7 +367,7 @@ describe("Transformer", () => {
367367
}
368368
],
369369
displayName: "Tariff M",
370-
id: 2,
370+
uuid: "3F8EC67A-314D-413F-996F-87CB9A28A56C",
371371
name: "Tariff M",
372372
slug: "tariff-m"
373373
},
@@ -383,7 +383,7 @@ describe("Transformer", () => {
383383
}
384384
],
385385
displayName: "Tariff L",
386-
id: 3,
386+
uuid: "DDDB5333-DCD7-40AF-A863-DD0E9249155A",
387387
name: "Tariff L",
388388
slug: "tariff-l"
389389
}

0 commit comments

Comments
 (0)