mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Start refactoring backend to pin posts on update
- we want to give the admins the ability to create posts, then pin them later, or pin other admins posts, etc...
This commit is contained in:
parent
56d88d6e84
commit
64f9d02c1a
@ -23,7 +23,6 @@ const createPostMutation = gql`
|
||||
$content: String!
|
||||
$language: String
|
||||
$categoryIds: [ID]
|
||||
$pinned: Boolean
|
||||
) {
|
||||
CreatePost(
|
||||
id: $id
|
||||
@ -31,7 +30,6 @@ const createPostMutation = gql`
|
||||
content: $content
|
||||
language: $language
|
||||
categoryIds: $categoryIds
|
||||
pinned: $pinned
|
||||
) {
|
||||
id
|
||||
title
|
||||
@ -52,7 +50,8 @@ const createPostMutation = gql`
|
||||
}
|
||||
`
|
||||
|
||||
beforeAll(() => {
|
||||
beforeAll(async () => {
|
||||
await factory.cleanDatabase()
|
||||
const { server } = createServer({
|
||||
context: () => {
|
||||
return {
|
||||
@ -374,86 +373,14 @@ describe('CreatePost', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('pinned posts', () => {
|
||||
beforeEach(async () => {
|
||||
variables = { ...variables, categoryIds: ['cat9', 'cat27', 'cat15'], pinned: true }
|
||||
})
|
||||
describe('users cannot create pinned posts', () => {
|
||||
it('throws authorization error', async () => {
|
||||
await expect(mutate({ mutation: createPostMutation, variables })).resolves.toMatchObject({
|
||||
errors: [{ message: 'Not Authorised!' }],
|
||||
data: { CreatePost: null },
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('moderator cannot create pinned posts', () => {
|
||||
let moderator
|
||||
beforeEach(async () => {
|
||||
moderator = await user.update({ role: 'moderator', updatedAt: new Date().toISOString() })
|
||||
authenticatedUser = await moderator.toJson()
|
||||
})
|
||||
|
||||
it('throws authorization error', async () => {
|
||||
await expect(mutate({ mutation: createPostMutation, variables })).resolves.toMatchObject({
|
||||
errors: [{ message: 'Not Authorised!' }],
|
||||
data: { CreatePost: null },
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('admin can create pinned posts', () => {
|
||||
let admin
|
||||
beforeEach(async () => {
|
||||
admin = await user.update({
|
||||
role: 'admin',
|
||||
name: 'Admin',
|
||||
updatedAt: new Date().toISOString(),
|
||||
})
|
||||
authenticatedUser = await admin.toJson()
|
||||
variables = {
|
||||
...variables,
|
||||
title: 'pinned post',
|
||||
content:
|
||||
'this is super important for the community and we promise not to have too many',
|
||||
}
|
||||
})
|
||||
|
||||
it('throws authorization error', async () => {
|
||||
const expected = {
|
||||
data: {
|
||||
CreatePost: {
|
||||
title: 'pinned post',
|
||||
content:
|
||||
'this is super important for the community and we promise not to have too many',
|
||||
author: {
|
||||
name: 'Admin',
|
||||
},
|
||||
pinnedBy: {
|
||||
id: 'current-user',
|
||||
name: 'Admin',
|
||||
role: 'admin',
|
||||
},
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
}
|
||||
|
||||
await expect(mutate({ mutation: createPostMutation, variables })).resolves.toMatchObject(
|
||||
expected,
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('UpdatePost', () => {
|
||||
let author, newlyCreatedPost
|
||||
const updatePostMutation = gql`
|
||||
mutation($id: ID!, $title: String!, $content: String!, $categoryIds: [ID]) {
|
||||
UpdatePost(id: $id, title: $title, content: $content, categoryIds: $categoryIds) {
|
||||
mutation($id: ID!, $title: String!, $content: String!, $categoryIds: [ID], $pinned: Boolean) {
|
||||
UpdatePost(id: $id, title: $title, content: $content, categoryIds: $categoryIds, pinned: $pinned) {
|
||||
id
|
||||
content
|
||||
categories {
|
||||
@ -641,6 +568,77 @@ describe('UpdatePost', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('pinned posts', () => {
|
||||
beforeEach(async () => {
|
||||
variables = { ...variables, categoryIds: ['cat9', 'cat27', 'cat15'], pinned: true }
|
||||
})
|
||||
describe('users cannot pin posts on update', () => {
|
||||
it.only('throws authorization error', async () => {
|
||||
await expect(mutate({ mutation: updatePostMutation, variables })).resolves.toMatchObject({
|
||||
errors: [{ message: 'Not Authorised!' }],
|
||||
data: { UpdatePost: null },
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('moderator cannot create pinned posts', () => {
|
||||
let moderator
|
||||
beforeEach(async () => {
|
||||
moderator = await user.update({ role: 'moderator', updatedAt: new Date().toISOString() })
|
||||
authenticatedUser = await moderator.toJson()
|
||||
})
|
||||
|
||||
it('throws authorization error', async () => {
|
||||
await expect(mutate({ mutation: createPostMutation, variables })).resolves.toMatchObject({
|
||||
errors: [{ message: 'Not Authorised!' }],
|
||||
data: { CreatePost: null },
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('admin can create pinned posts', () => {
|
||||
let admin
|
||||
beforeEach(async () => {
|
||||
admin = await user.update({
|
||||
role: 'admin',
|
||||
name: 'Admin',
|
||||
updatedAt: new Date().toISOString(),
|
||||
})
|
||||
authenticatedUser = await admin.toJson()
|
||||
variables = {
|
||||
...variables,
|
||||
title: 'pinned post',
|
||||
content: 'this is super important for the community and we promise not to have too many',
|
||||
}
|
||||
})
|
||||
|
||||
it('throws authorization error', async () => {
|
||||
const expected = {
|
||||
data: {
|
||||
CreatePost: {
|
||||
title: 'pinned post',
|
||||
content:
|
||||
'this is super important for the community and we promise not to have too many',
|
||||
author: {
|
||||
name: 'Admin',
|
||||
},
|
||||
pinnedBy: {
|
||||
id: 'current-user',
|
||||
name: 'Admin',
|
||||
role: 'admin',
|
||||
},
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
}
|
||||
|
||||
await expect(mutate({ mutation: createPostMutation, variables })).resolves.toMatchObject(
|
||||
expected,
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('DeletePost', () => {
|
||||
|
||||
@ -16,6 +16,9 @@ type Post {
|
||||
createdAt: String
|
||||
updatedAt: String
|
||||
language: String
|
||||
pinnedAt: String @cypher(
|
||||
statement: "MATCH (this)<-[pinned:PINNED]-(:User) WHERE NOT this.deleted = true AND NOT this.disabled = true RETURN this.createdAt"
|
||||
)
|
||||
pinnedBy: User @relation(name:"PINNED", direction: "IN")
|
||||
relatedContributions: [Post]!
|
||||
@cypher(
|
||||
@ -69,7 +72,6 @@ type Mutation {
|
||||
language: String
|
||||
categoryIds: [ID]
|
||||
contentExcerpt: String
|
||||
pinned: Boolean
|
||||
): Post
|
||||
UpdatePost(
|
||||
id: ID!
|
||||
@ -82,6 +84,7 @@ type Mutation {
|
||||
visibility: Visibility
|
||||
language: String
|
||||
categoryIds: [ID]
|
||||
pinned: Boolean
|
||||
): Post
|
||||
DeletePost(id: ID!): Post
|
||||
AddPostEmotions(to: _PostInput!, data: _EMOTEDInput!): EMOTED
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user