mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Massive refactoring of factories
cc @mattwr18 @tirokk @ulfgebhardt @appinteractive The factories don't use string interpolation now but they use variables. This resolves some errors of escaping strings when you send html along with `post.content`. It is much cleaner, too.
This commit is contained in:
parent
a4de87318d
commit
0811ca8248
@ -3,21 +3,26 @@ import uuid from 'uuid/v4'
|
||||
export default function (params) {
|
||||
const {
|
||||
id = uuid(),
|
||||
key,
|
||||
key = '',
|
||||
type = 'crowdfunding',
|
||||
status = 'permanent',
|
||||
icon
|
||||
icon = '/img/badges/indiegogo_en_panda.svg'
|
||||
} = params
|
||||
|
||||
return `
|
||||
mutation {
|
||||
CreateBadge(
|
||||
id: "${id}",
|
||||
key: "${key}",
|
||||
type: ${type},
|
||||
status: ${status},
|
||||
icon: "${icon}"
|
||||
) { id }
|
||||
return {
|
||||
mutation: `
|
||||
mutation(
|
||||
$id: ID
|
||||
$key: String!
|
||||
$type: BadgeTypeEnum!
|
||||
$status: BadgeStatusEnum!
|
||||
$icon: String!
|
||||
) {
|
||||
CreateBadge(id: $id, key: $key, type: $type, status: $status, icon: $icon) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: { id, key, type, status, icon }
|
||||
}
|
||||
`
|
||||
}
|
||||
|
||||
@ -8,14 +8,15 @@ export default function (params) {
|
||||
icon
|
||||
} = params
|
||||
|
||||
return `
|
||||
mutation {
|
||||
CreateCategory(
|
||||
id: "${id}",
|
||||
name: "${name}",
|
||||
slug: "${slug}",
|
||||
icon: "${icon}"
|
||||
) { id, name }
|
||||
return {
|
||||
mutation: `
|
||||
mutation($id: ID, $name: String!, $slug: String, $icon: String!) {
|
||||
CreateCategory(id: $id, name: $name, slug: $slug, icon: $icon) {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
`
|
||||
`,
|
||||
variables: { id, name, slug, icon }
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,19 +7,17 @@ export default function (params) {
|
||||
content = [
|
||||
faker.lorem.sentence(),
|
||||
faker.lorem.sentence()
|
||||
].join('. '),
|
||||
disabled = false,
|
||||
deleted = false
|
||||
].join('. ')
|
||||
} = params
|
||||
|
||||
return `
|
||||
mutation {
|
||||
CreateComment(
|
||||
id: "${id}",
|
||||
content: "${content}",
|
||||
disabled: ${disabled},
|
||||
deleted: ${deleted}
|
||||
) { id }
|
||||
}
|
||||
`
|
||||
return {
|
||||
mutation: `
|
||||
mutation($id: ID!, $content: String!) {
|
||||
CreateComment(id: $id, content: $content) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: { id, content }
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,8 +71,8 @@ export default function Factory (options = {}) {
|
||||
return this
|
||||
},
|
||||
async create (node, properties) {
|
||||
const mutation = this.factories[node](properties)
|
||||
this.lastResponse = await this.graphQLClient.request(mutation)
|
||||
const { mutation, variables } = this.factories[node](properties)
|
||||
this.lastResponse = await this.graphQLClient.request(mutation, variables)
|
||||
return this
|
||||
},
|
||||
async relate (node, relationship, properties) {
|
||||
|
||||
@ -6,12 +6,15 @@ export default function (params) {
|
||||
read = false
|
||||
} = params
|
||||
|
||||
return `
|
||||
mutation {
|
||||
CreateNotification(
|
||||
id: "${id}",
|
||||
read: ${read},
|
||||
) { id, read }
|
||||
}
|
||||
`
|
||||
return {
|
||||
mutation: `
|
||||
mutation($id: ID, $read: Boolean) {
|
||||
CreateNotification(id: $id, read: $read) {
|
||||
id
|
||||
read
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: { id, read }
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,20 +5,17 @@ export default function create (params) {
|
||||
const {
|
||||
id = uuid(),
|
||||
name = faker.company.companyName(),
|
||||
description = faker.company.catchPhrase(),
|
||||
disabled = false,
|
||||
deleted = false
|
||||
description = faker.company.catchPhrase()
|
||||
} = params
|
||||
|
||||
return `
|
||||
mutation {
|
||||
CreateOrganization(
|
||||
id: "${id}",
|
||||
name: "${name}",
|
||||
description: "${description}",
|
||||
disabled: ${disabled},
|
||||
deleted: ${deleted}
|
||||
) { name }
|
||||
}
|
||||
`
|
||||
return {
|
||||
mutation: `
|
||||
mutation($id: ID!, $name: String!, $description: String!) {
|
||||
CreateOrganization(id: $id, name: $name, description: $description) {
|
||||
name
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: { id, name, description }
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,17 +18,31 @@ export default function (params) {
|
||||
deleted = false
|
||||
} = params
|
||||
|
||||
return `
|
||||
mutation {
|
||||
CreatePost(
|
||||
id: "${id}",
|
||||
slug: "${slug}",
|
||||
title: "${title}",
|
||||
content: "${content}",
|
||||
image: "${image}",
|
||||
visibility: ${visibility},
|
||||
deleted: ${deleted}
|
||||
) { title, content }
|
||||
}
|
||||
`
|
||||
return {
|
||||
mutation: `
|
||||
mutation(
|
||||
$id: ID!
|
||||
$slug: String
|
||||
$title: String!
|
||||
$content: String!
|
||||
$image: String
|
||||
$visibility: VisibilityEnum
|
||||
$deleted: Boolean
|
||||
) {
|
||||
CreatePost(
|
||||
id: $id
|
||||
slug: $slug
|
||||
title: $title
|
||||
content: $content
|
||||
image: $image
|
||||
visibility: $visibility
|
||||
deleted: $deleted
|
||||
) {
|
||||
title
|
||||
content
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: { id, slug, title, content, image, visibility, deleted }
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,15 +6,15 @@ export default function create (params) {
|
||||
id
|
||||
} = params
|
||||
|
||||
return `
|
||||
mutation {
|
||||
report(
|
||||
description: "${description}",
|
||||
id: "${id}",
|
||||
) {
|
||||
id,
|
||||
createdAt
|
||||
return {
|
||||
mutation: `
|
||||
mutation($id: ID!, $description: String!) {
|
||||
report(description: $description, id: $id) {
|
||||
id
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
`,
|
||||
variables: { id, description }
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,15 +3,17 @@ import uuid from 'uuid/v4'
|
||||
export default function (params) {
|
||||
const {
|
||||
id = uuid(),
|
||||
name
|
||||
name = '#human-connection'
|
||||
} = params
|
||||
|
||||
return `
|
||||
mutation {
|
||||
CreateTag(
|
||||
id: "${id}",
|
||||
name: "${name}",
|
||||
) { name }
|
||||
}
|
||||
`
|
||||
return {
|
||||
mutation: `
|
||||
mutation($id: ID!, $name: String!) {
|
||||
CreateTag(id: $id, name: $name) {
|
||||
name
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: { id, name }
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,34 +10,42 @@ export default function create (params) {
|
||||
password = '1234',
|
||||
role = 'user',
|
||||
avatar = faker.internet.avatar(),
|
||||
about = faker.lorem.paragraph(),
|
||||
disabled = false,
|
||||
deleted = false
|
||||
about = faker.lorem.paragraph()
|
||||
} = params
|
||||
|
||||
return `
|
||||
mutation {
|
||||
CreateUser(
|
||||
id: "${id}",
|
||||
name: "${name}",
|
||||
slug: "${slug}",
|
||||
password: "${password}",
|
||||
email: "${email}",
|
||||
avatar: "${avatar}",
|
||||
about: "${about}",
|
||||
role: ${role},
|
||||
disabled: ${disabled},
|
||||
deleted: ${deleted}
|
||||
return {
|
||||
mutation: `
|
||||
mutation(
|
||||
$id: ID!
|
||||
$name: String
|
||||
$slug: String
|
||||
$password: String!
|
||||
$email: String
|
||||
$avatar: String
|
||||
$about: String
|
||||
$role: UserGroupEnum
|
||||
) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
email
|
||||
avatar
|
||||
role
|
||||
deleted
|
||||
disabled
|
||||
CreateUser(
|
||||
id: $id
|
||||
name: $name
|
||||
slug: $slug
|
||||
password: $password
|
||||
email: $email
|
||||
avatar: $avatar
|
||||
about: $about
|
||||
role: $role
|
||||
) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
email
|
||||
avatar
|
||||
role
|
||||
deleted
|
||||
disabled
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
`,
|
||||
variables: { id, name, slug, password, email, avatar, about, role }
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user