2023-03-13 12:55:59 -07:00
|
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
|
|
|
2023-05-01 09:01:39 -07:00
|
|
|
import {
|
2023-05-02 16:30:21 -07:00
|
|
|
adSchema,
|
|
|
|
cardSchema,
|
2023-05-01 09:01:39 -07:00
|
|
|
groupSchema,
|
|
|
|
groupRelationshipSchema,
|
|
|
|
groupTagSchema,
|
2023-05-02 16:49:13 -07:00
|
|
|
relationshipSchema,
|
2023-05-02 16:30:21 -07:00
|
|
|
type Ad,
|
|
|
|
type Card,
|
2023-05-01 09:01:39 -07:00
|
|
|
type Group,
|
|
|
|
type GroupRelationship,
|
|
|
|
type GroupTag,
|
2023-05-02 16:49:13 -07:00
|
|
|
type Relationship,
|
2023-05-01 09:01:39 -07:00
|
|
|
} from 'soapbox/schemas';
|
2023-03-13 12:55:59 -07:00
|
|
|
|
|
|
|
// TODO: there's probably a better way to create these factory functions.
|
|
|
|
// This looks promising but didn't work on my first attempt: https://github.com/anatine/zod-plugins/tree/main/packages/zod-mock
|
|
|
|
|
2023-05-02 16:30:21 -07:00
|
|
|
function buildCard(props: Partial<Card> = {}): Card {
|
|
|
|
return cardSchema.parse(Object.assign({
|
|
|
|
url: 'https://soapbox.test',
|
|
|
|
}, props));
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildGroup(props: Partial<Group> = {}): Group {
|
2023-03-13 12:55:59 -07:00
|
|
|
return groupSchema.parse(Object.assign({
|
|
|
|
id: uuidv4(),
|
|
|
|
}, props));
|
|
|
|
}
|
|
|
|
|
2023-05-02 16:30:21 -07:00
|
|
|
function buildGroupRelationship(props: Partial<GroupRelationship> = {}): GroupRelationship {
|
2023-03-13 12:55:59 -07:00
|
|
|
return groupRelationshipSchema.parse(Object.assign({
|
|
|
|
id: uuidv4(),
|
|
|
|
}, props));
|
|
|
|
}
|
|
|
|
|
2023-05-02 16:30:21 -07:00
|
|
|
function buildGroupTag(props: Partial<GroupTag> = {}): GroupTag {
|
2023-05-01 09:01:39 -07:00
|
|
|
return groupTagSchema.parse(Object.assign({
|
|
|
|
id: uuidv4(),
|
|
|
|
}, props));
|
|
|
|
}
|
|
|
|
|
2023-05-02 16:30:21 -07:00
|
|
|
function buildAd(props: Partial<Ad> = {}): Ad {
|
|
|
|
return adSchema.parse(Object.assign({
|
|
|
|
card: buildCard(),
|
|
|
|
}, props));
|
|
|
|
}
|
|
|
|
|
2023-05-02 16:49:13 -07:00
|
|
|
function buildRelationship(props: Partial<Relationship> = {}): Relationship {
|
|
|
|
return relationshipSchema.parse(Object.assign({
|
|
|
|
id: uuidv4(),
|
|
|
|
}, props));
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
buildCard,
|
|
|
|
buildGroup,
|
|
|
|
buildGroupRelationship,
|
|
|
|
buildGroupTag,
|
|
|
|
buildAd,
|
|
|
|
buildRelationship,
|
|
|
|
};
|