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

Track deps #2

Merged
merged 1 commit into from
Apr 4, 2020
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
140 changes: 78 additions & 62 deletions src/convert.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// import { arbitraryQuery } from "../output/output";
import * as Codegen from "./convert";
import * as Types from "./types";

describe("includesOneOf", () => {
it("Makes any sense whatsoever", () => {
Expand All @@ -18,26 +19,30 @@ describe("includesOneOf", () => {

describe("sortASTs", () => {
it("Puts mentions later", () => {
const stable: Codegen.NamedType = [
"Object",
"Stable" as Codegen.TypeName,
"fc.record({horse: arbitraryHorse })"
];
const horse: Codegen.NamedType = [
"Object",
"Horse" as Codegen.TypeName,
"fc.record({saddle: arbitrarySaddle})"
];
const saddle: Codegen.NamedType = [
"Object",
"Saddle" as Codegen.TypeName,
"fc.record({chair: arbitraryChair})"
];
const things: Codegen.NamedType = [
"Union",
"Things" as Codegen.TypeName,
"fc.oneof(arbitraryStable, arbitrarySaddle)"
];
const stable: Types.Output = {
kind: "Object",
name: "Stable" as Types.TypeName,
output: "fc.record({horse: arbitraryHorse })" as Types.Generated,
deps: [],
};
const horse: Types.Output = {
kind: "Object",
name: "Horse" as Types.TypeName,
output: "fc.record({saddle: arbitrarySaddle})" as Types.Generated,
deps: [],
};
const saddle: Types.Output = {
kind: "Object",
name: "Saddle" as Types.TypeName,
output: "fc.record({chair: arbitraryChair})" as Types.Generated,
deps: [],
};
const things: Types.Output = {
kind: "Union",
name: "Things" as Types.TypeName,
output: "fc.oneof(arbitraryStable, arbitrarySaddle)" as Types.Generated,
deps: [],
};
const expectedOrder = [saddle, horse, stable, things];
expect(Codegen.sortASTs([things, stable, horse, saddle])).toStrictEqual(
expectedOrder
Expand All @@ -48,46 +53,57 @@ describe("sortASTs", () => {
});

it("Does the twitter ones", () => {
const Query: Codegen.NamedType = [
"Object",
"Query" as Codegen.TypeName,
`fc.record({Tweet: arbitraryTweet,Tweets: fc.array(arbitraryTweet),TweetsMeta: arbitraryMeta,User: arbitraryUser,Notifications: fc.array(arbitraryNotification),NotificationsMeta: arbitraryMeta})`
];
const Tweet: Codegen.NamedType = [
"Object",
"Tweet" as Codegen.TypeName,
`fc.record({id: arbitraryID,body: arbitraryString,date: arbitraryDate,Author: arbitraryUser,Stats: arbitraryStat})`
];
const User: Codegen.NamedType = [
"Object",
"User" as Codegen.TypeName,
`fc.record({id: arbitraryID,username: arbitraryString,first_name: arbitraryString,last_name: arbitraryString,full_name: arbitraryString,name: arbitraryString,avatar_url: arbitraryUrl})`
];
const Stat: Codegen.NamedType = [
"Object",
"Stat" as Codegen.TypeName,
`fc.record({views: arbitraryInt,likes: arbitraryInt,retweets: arbitraryInt,responses: arbitraryInt})`
];
const Meta: Codegen.NamedType = [
"Object",
"Meta" as Codegen.TypeName,
`fc.record({count: arbitraryInt})`
];
const Notification: Codegen.NamedType = [
"Object",
"Notification" as Codegen.TypeName,
`fc.record({id: arbitraryID,date: arbitraryDate,type: arbitraryString})`
];
const Mutation: Codegen.NamedType = [
"Object",
"Mutation" as Codegen.TypeName,
`fc.record({createTweet: arbitraryTweet,deleteTweet: arbitraryTweet,markTweetRead: arbitraryBoolean})`
];
const StatOrNotification: Codegen.NamedType = [
"Union",
"StatOrNotification" as Codegen.TypeName,
`fc.oneof(arbitraryStat, arbitraryNotification)`
];
const Query: Types.Output = {
kind: "Object",
name: "Query" as Types.TypeName,
output: `fc.record({Tweet: arbitraryTweet,Tweets: fc.array(arbitraryTweet),TweetsMeta: arbitraryMeta,User: arbitraryUser,Notifications: fc.array(arbitraryNotification),NotificationsMeta: arbitraryMeta})` as Types.Generated,
deps: [],
};
const Tweet: Types.Output = {
kind: "Object",
name: "Tweet" as Types.TypeName,
output: `fc.record({id: arbitraryID,body: arbitraryString,date: arbitraryDate,Author: arbitraryUser,Stats: arbitraryStat})` as Types.Generated,
deps: [],
};
const User: Types.Output = {
kind: "Object",
name: "User" as Types.TypeName,
output: `fc.record({id: arbitraryID,username: arbitraryString,first_name: arbitraryString,last_name: arbitraryString,full_name: arbitraryString,name: arbitraryString,avatar_url: arbitraryUrl})` as Types.Generated,
deps: [],
};
const Stat: Types.Output = {
kind: "Object",
name: "Stat" as Types.TypeName,
output: `fc.record({views: arbitraryInt,likes: arbitraryInt,retweets: arbitraryInt,responses: arbitraryInt})` as Types.Generated,
deps: [],
};
const Meta: Types.Output = {
kind: "Object",
name: "Meta" as Types.TypeName,
output: `fc.record({count: arbitraryInt})` as Types.Generated,
deps: [],
};

const Notification: Types.Output = {
kind: "Object",
name: "Notification" as Types.TypeName,
output: `fc.record({id: arbitraryID,date: arbitraryDate,type: arbitraryString})` as Types.Generated,
deps: [],
};

const Mutation: Types.Output = {
kind: "Object",
name: "Mutation" as Types.TypeName,
output: `fc.record({createTweet: arbitraryTweet,deleteTweet: arbitraryTweet,markTweetRead: arbitraryBoolean})` as Types.Generated,
deps: [],
};

const StatOrNotification: Types.Output = {
kind: "Union",
name: "StatOrNotification" as Types.TypeName,
output: `fc.oneof(arbitraryStat, arbitraryNotification)` as Types.Generated,
deps: [],
};

const expectedTweetOrder = [
User,
Expand All @@ -97,7 +113,7 @@ describe("sortASTs", () => {
Notification,
Query,
Mutation,
StatOrNotification
StatOrNotification,
];
expect(
Codegen.sortASTs([
Expand All @@ -108,7 +124,7 @@ describe("sortASTs", () => {
Meta,
Notification,
Mutation,
StatOrNotification
StatOrNotification,
])
).toStrictEqual(expectedTweetOrder);
});
Expand Down
Loading