-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,166 additions
and
994 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import { Post, setupMockData } from "../../support/mock-data"; | ||
import { Data } from "../../../src/support/interfaces"; | ||
import { recordGraphQLRequest } from "../../support/helpers"; | ||
|
||
let store: any; | ||
let vuexOrmGraphQL; | ||
|
||
describe("custom mutation", () => { | ||
beforeEach(async () => { | ||
[store, vuexOrmGraphQL] = await setupMockData(); | ||
}); | ||
|
||
describe("via Model.mutate", () => { | ||
test("sends the correct query to the API", async () => { | ||
// @ts-ignore | ||
await Post.fetch(1); | ||
const post: Data = Post.find(1)! as Data; | ||
|
||
const request = await recordGraphQLRequest(async () => { | ||
// @ts-ignore | ||
await Post.mutate({ name: "upvotePost", args: { captchaToken: "15", id: post.id } }); | ||
}); | ||
|
||
expect(request!.variables.captchaToken).toEqual("15"); | ||
expect(request!.variables.id).toEqual(post.id); | ||
expect(request!.query).toEqual( | ||
` | ||
mutation UpvotePost($captchaToken: String!, $id: ID!) { | ||
upvotePost(captchaToken: $captchaToken, id: $id) { | ||
id | ||
content | ||
title | ||
otherId | ||
published | ||
author { | ||
id | ||
name | ||
profile { | ||
id | ||
age | ||
sex | ||
} | ||
} | ||
comments { | ||
nodes { | ||
id | ||
content | ||
subjectId | ||
subjectType | ||
author { | ||
id | ||
name | ||
profile { | ||
id | ||
age | ||
sex | ||
} | ||
} | ||
} | ||
} | ||
tags { | ||
nodes { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
} | ||
`.trim() + "\n" | ||
); | ||
}); | ||
}); | ||
|
||
describe("via post.$mutate", () => { | ||
test("sends the correct query to the API", async () => { | ||
// @ts-ignore | ||
await Post.fetch(1); | ||
const post: Data = Post.find(1)! as Data; | ||
|
||
const request = await recordGraphQLRequest(async () => { | ||
// @ts-ignore | ||
await post.$mutate({ name: "upvotePost", args: { captchaToken: "15" } }); | ||
}); | ||
|
||
expect(request!.variables.captchaToken).toEqual("15"); | ||
expect(request!.variables.id).toEqual(post.id); | ||
expect(request!.query).toEqual( | ||
` | ||
mutation UpvotePost($captchaToken: String!, $id: ID!) { | ||
upvotePost(captchaToken: $captchaToken, id: $id) { | ||
id | ||
content | ||
title | ||
otherId | ||
published | ||
author { | ||
id | ||
name | ||
profile { | ||
id | ||
age | ||
sex | ||
} | ||
} | ||
comments { | ||
nodes { | ||
id | ||
content | ||
subjectId | ||
subjectType | ||
author { | ||
id | ||
name | ||
profile { | ||
id | ||
age | ||
sex | ||
} | ||
} | ||
} | ||
} | ||
tags { | ||
nodes { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
} | ||
`.trim() + "\n" | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { Post, setupMockData } from "../../support/mock-data"; | ||
import { Data } from "../../../src/support/interfaces"; | ||
import { recordGraphQLRequest } from "../../support/helpers"; | ||
|
||
let store: any; | ||
let vuexOrmGraphQL; | ||
|
||
describe("custom query", () => { | ||
beforeEach(async () => { | ||
[store, vuexOrmGraphQL] = await setupMockData(); | ||
}); | ||
|
||
test("via Model method sends the correct query to the API", async () => { | ||
const request = await recordGraphQLRequest(async () => { | ||
// @ts-ignore | ||
await Post.customQuery({ name: "unpublishedPosts", filter: { authorId: 3 } }); | ||
}); | ||
|
||
expect(request!.variables.authorId).toEqual(3); | ||
expect(request!.query).toEqual( | ||
` | ||
query UnpublishedPosts($authorId: ID!) { | ||
unpublishedPosts(authorId: $authorId) { | ||
nodes { | ||
id | ||
content | ||
title | ||
otherId | ||
published | ||
author { | ||
id | ||
name | ||
profile { | ||
id | ||
age | ||
sex | ||
} | ||
} | ||
comments { | ||
nodes { | ||
id | ||
content | ||
subjectId | ||
subjectType | ||
author { | ||
id | ||
name | ||
profile { | ||
id | ||
age | ||
sex | ||
} | ||
} | ||
} | ||
} | ||
tags { | ||
nodes { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`.trim() + "\n" | ||
); | ||
}); | ||
|
||
test("via record method sends the correct query to the API", async () => { | ||
// @ts-ignore | ||
await Post.fetch(1); | ||
const post: Data = Post.find(1)! as Data; | ||
|
||
const request = await recordGraphQLRequest(async () => { | ||
await post.$customQuery({ name: "unpublishedPosts", filter: { authorId: 2 } }); | ||
}); | ||
|
||
expect(request!.variables.authorId).toEqual(2); | ||
expect(request!.variables.id).toEqual(1); | ||
expect(request!.query).toEqual( | ||
` | ||
query UnpublishedPosts($authorId: ID!, $id: ID!) { | ||
unpublishedPosts(authorId: $authorId, id: $id) { | ||
nodes { | ||
id | ||
content | ||
title | ||
otherId | ||
published | ||
author { | ||
id | ||
name | ||
profile { | ||
id | ||
age | ||
sex | ||
} | ||
} | ||
comments { | ||
nodes { | ||
id | ||
content | ||
subjectId | ||
subjectType | ||
author { | ||
id | ||
name | ||
profile { | ||
id | ||
age | ||
sex | ||
} | ||
} | ||
} | ||
} | ||
tags { | ||
nodes { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`.trim() + "\n" | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Post, setupMockData } from "../../support/mock-data"; | ||
import { Data } from "../../../src/support/interfaces"; | ||
import { recordGraphQLRequest } from "../../support/helpers"; | ||
|
||
let store: any; | ||
let vuexOrmGraphQL; | ||
|
||
describe("deleteAndDestroy", () => { | ||
beforeEach(async () => { | ||
[store, vuexOrmGraphQL] = await setupMockData(); | ||
}); | ||
|
||
test("sends the correct query to the API and deletes the record", async () => { | ||
// @ts-ignore | ||
await Post.fetch(1); | ||
const post: Data = Post.find(1)! as Data; | ||
|
||
const request = await recordGraphQLRequest(async () => { | ||
await post.$deleteAndDestroy(); | ||
}); | ||
|
||
expect(request!.variables).toEqual({ id: 1 }); | ||
expect(request!.query).toEqual( | ||
` | ||
mutation DeletePost($id: ID!) { | ||
deletePost(id: $id) { | ||
id | ||
content | ||
title | ||
otherId | ||
published | ||
author { | ||
id | ||
name | ||
profile { | ||
id | ||
age | ||
sex | ||
} | ||
} | ||
comments { | ||
nodes { | ||
id | ||
content | ||
subjectId | ||
subjectType | ||
author { | ||
id | ||
name | ||
profile { | ||
id | ||
age | ||
sex | ||
} | ||
} | ||
} | ||
} | ||
tags { | ||
nodes { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
} | ||
`.trim() + "\n" | ||
); | ||
|
||
expect(await Post.find(1)).toEqual(null); | ||
}); | ||
}); |
Oops, something went wrong.