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-05 05:35:11 -07:00
|
|
|
accountSchema,
|
2023-05-02 16:30:21 -07:00
|
|
|
adSchema,
|
|
|
|
cardSchema,
|
2023-05-05 05:35:11 -07:00
|
|
|
groupMemberSchema,
|
2023-05-01 09:01:39 -07:00
|
|
|
groupRelationshipSchema,
|
2023-05-05 05:35:11 -07:00
|
|
|
groupSchema,
|
2023-05-01 09:01:39 -07:00
|
|
|
groupTagSchema,
|
2023-05-02 16:49:13 -07:00
|
|
|
relationshipSchema,
|
2023-06-20 12:24:39 -07:00
|
|
|
statusSchema,
|
2023-05-05 05:35:11 -07:00
|
|
|
type Account,
|
2023-05-02 16:30:21 -07:00
|
|
|
type Ad,
|
|
|
|
type Card,
|
2023-05-01 09:01:39 -07:00
|
|
|
type Group,
|
2023-05-05 05:35:11 -07:00
|
|
|
type GroupMember,
|
2023-05-01 09:01:39 -07:00
|
|
|
type GroupRelationship,
|
|
|
|
type GroupTag,
|
2023-05-02 16:49:13 -07:00
|
|
|
type Relationship,
|
2023-05-12 18:50:30 -07:00
|
|
|
type Status,
|
2023-05-01 09:01:39 -07:00
|
|
|
} from 'soapbox/schemas';
|
2023-05-05 05:35:11 -07:00
|
|
|
import { GroupRoles } from 'soapbox/schemas/group-member';
|
2023-03-13 12:55:59 -07:00
|
|
|
|
2023-06-20 12:24:39 -07:00
|
|
|
import type { PartialDeep } from 'type-fest';
|
|
|
|
|
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-06-20 12:24:39 -07:00
|
|
|
function buildAccount(props: PartialDeep<Account> = {}): Account {
|
2023-05-05 05:35:11 -07:00
|
|
|
return accountSchema.parse(Object.assign({
|
|
|
|
id: uuidv4(),
|
|
|
|
}, props));
|
|
|
|
}
|
|
|
|
|
2023-06-20 12:24:39 -07:00
|
|
|
function buildCard(props: PartialDeep<Card> = {}): Card {
|
2023-05-02 16:30:21 -07:00
|
|
|
return cardSchema.parse(Object.assign({
|
|
|
|
url: 'https://soapbox.test',
|
|
|
|
}, props));
|
|
|
|
}
|
|
|
|
|
2023-06-20 12:24:39 -07:00
|
|
|
function buildGroup(props: PartialDeep<Group> = {}): Group {
|
2023-03-13 12:55:59 -07:00
|
|
|
return groupSchema.parse(Object.assign({
|
|
|
|
id: uuidv4(),
|
2023-05-31 05:57:43 -07:00
|
|
|
owner: {
|
|
|
|
id: uuidv4(),
|
|
|
|
},
|
2023-03-13 12:55:59 -07:00
|
|
|
}, props));
|
|
|
|
}
|
|
|
|
|
2023-06-20 12:24:39 -07:00
|
|
|
function buildGroupRelationship(props: PartialDeep<GroupRelationship> = {}): GroupRelationship {
|
2023-03-13 12:55:59 -07:00
|
|
|
return groupRelationshipSchema.parse(Object.assign({
|
|
|
|
id: uuidv4(),
|
|
|
|
}, props));
|
|
|
|
}
|
|
|
|
|
2023-06-20 12:24:39 -07:00
|
|
|
function buildGroupTag(props: PartialDeep<GroupTag> = {}): GroupTag {
|
2023-05-01 09:01:39 -07:00
|
|
|
return groupTagSchema.parse(Object.assign({
|
|
|
|
id: uuidv4(),
|
2023-05-05 05:35:11 -07:00
|
|
|
name: uuidv4(),
|
|
|
|
}, props));
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildGroupMember(
|
2023-06-20 12:24:39 -07:00
|
|
|
props: PartialDeep<GroupMember> = {},
|
|
|
|
accountProps: PartialDeep<Account> = {},
|
2023-05-05 05:35:11 -07:00
|
|
|
): GroupMember {
|
|
|
|
return groupMemberSchema.parse(Object.assign({
|
|
|
|
id: uuidv4(),
|
|
|
|
account: buildAccount(accountProps),
|
|
|
|
role: GroupRoles.USER,
|
2023-05-01 09:01:39 -07:00
|
|
|
}, props));
|
|
|
|
}
|
|
|
|
|
2023-06-20 12:24:39 -07:00
|
|
|
function buildAd(props: PartialDeep<Ad> = {}): Ad {
|
2023-05-02 16:30:21 -07:00
|
|
|
return adSchema.parse(Object.assign({
|
|
|
|
card: buildCard(),
|
|
|
|
}, props));
|
|
|
|
}
|
|
|
|
|
2023-06-20 12:24:39 -07:00
|
|
|
function buildRelationship(props: PartialDeep<Relationship> = {}): Relationship {
|
2023-05-02 16:49:13 -07:00
|
|
|
return relationshipSchema.parse(Object.assign({
|
|
|
|
id: uuidv4(),
|
|
|
|
}, props));
|
|
|
|
}
|
|
|
|
|
2023-06-20 12:24:39 -07:00
|
|
|
function buildStatus(props: PartialDeep<Status> = {}) {
|
|
|
|
return statusSchema.parse(Object.assign({
|
2023-05-08 10:29:11 -07:00
|
|
|
id: uuidv4(),
|
2023-06-20 14:57:40 -07:00
|
|
|
account: buildAccount(),
|
2023-05-08 10:29:11 -07:00
|
|
|
}, props));
|
|
|
|
}
|
|
|
|
|
2023-05-02 16:49:13 -07:00
|
|
|
export {
|
2023-06-20 12:24:39 -07:00
|
|
|
buildAccount,
|
2023-05-05 05:35:11 -07:00
|
|
|
buildAd,
|
2023-05-02 16:49:13 -07:00
|
|
|
buildCard,
|
|
|
|
buildGroup,
|
2023-05-05 05:35:11 -07:00
|
|
|
buildGroupMember,
|
2023-05-02 16:49:13 -07:00
|
|
|
buildGroupRelationship,
|
|
|
|
buildGroupTag,
|
|
|
|
buildRelationship,
|
2023-05-08 10:29:11 -07:00
|
|
|
buildStatus,
|
2023-05-02 16:49:13 -07:00
|
|
|
};
|