The test case data structure type looks like this:
export type type User = {
name: UserName;
email: Email;
createdAt: Date;
updatedAt: Date;
subscription: SubscriptionType;
stripeId: StripeId;
visits: Visits;
favouriteColours: Set<Colour>;
profile: Profile;
fileSystem: FileSystemItem;
}
User = {
name: stringname: type UserName = stringUserName;
email: stringemail: type Email = stringEmail;
createdAt: DatecreatedAt: Date;
updatedAt: DateupdatedAt: Date;
subscription: SubscriptionTypesubscription: type SubscriptionType = "pro" | "basic" | "free"SubscriptionType;
stripeId: `cus_${string}`stripeId: type StripeId = `cus_${string}`StripeId;
visits: numbervisits: type Visits = numberVisits;
favouriteColours: Set<Colour>favouriteColours: interface Set<T>Set<type Colour = PresetColours | `#${string}`Colour>;
profile: Profileprofile: type Profile = {
type: 'listener';
boughtTracks: NonNegativeInteger;
} | {
type: 'artist';
publishedTracks: NonNegativeInteger;
}
Profile;
fileSystem: FileSystemItemfileSystem: type FileSystemItem = {
name: FileName;
} & ({
type: 'directory';
children: FileSystemItem[];
} | {
type: 'file';
})
FileSystemItem;
};
type type SubscriptionType = "pro" | "basic" | "free"SubscriptionType = 'pro' | 'basic' | 'free';
type type FileSystemItem = {
name: FileName;
} & ({
type: 'directory';
children: FileSystemItem[];
} | {
type: 'file';
})
FileSystemItem = {
name: stringname: type FileName = stringFileName;
} & (
| {
type: "directory"type: 'directory';
children: FileSystemItem[]children: type FileSystemItem = {
name: FileName;
} & ({
type: 'directory';
children: FileSystemItem[];
} | {
type: 'file';
})
FileSystemItem[];
}
| {
type: "file"type: 'file';
}
);
type type Profile = {
type: 'listener';
boughtTracks: NonNegativeInteger;
} | {
type: 'artist';
publishedTracks: NonNegativeInteger;
}
Profile =
| {
type: "listener"type: 'listener';
boughtTracks: numberboughtTracks: type NonNegativeInteger = numberNonNegativeInteger;
}
| {
type: "artist"type: 'artist';
publishedTracks: numberpublishedTracks: type NonNegativeInteger = numberNonNegativeInteger;
};
// every type here is to be checked and nominal-typed by validators
type type NonEmptyString = stringNonEmptyString = string;
type type UserName = stringUserName = type NonEmptyString = stringNonEmptyString;
type type Email = stringEmail = type NonEmptyString = stringNonEmptyString;
type type StripeId = `cus_${string}`StripeId = `cus_${string}`;
type type NonNegativeInteger = numberNonNegativeInteger = number;
type type Visits = numberVisits = type NonNegativeInteger = numberNonNegativeInteger;
type type PresetColours = "red" | "green" | "blue"PresetColours = 'red' | 'green' | 'blue';
type type HexColour = `#${string}`HexColour = `#${string}`;
type type Colour = PresetColours | `#${string}`Colour = type PresetColours = "red" | "green" | "blue"PresetColours | type HexColour = `#${string}`HexColour;
type type FileName = stringFileName = string;
Most of the tests are performed automatically, the others you have to take my word for it (or check the code). PRs are welcome.
More detailed test case description and more context can be found in my blog post.