mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Start refactor of authenticated user path
- Refactor report invlid resource - Start refactor of valid resource path
This commit is contained in:
parent
cf5042d9a4
commit
bcb880db5e
@ -8,8 +8,8 @@ const factory = Factory()
|
|||||||
const instance = getNeode()
|
const instance = getNeode()
|
||||||
const driver = getDriver()
|
const driver = getDriver()
|
||||||
|
|
||||||
describe('report',()=>{
|
describe('report', () => {
|
||||||
let authenticatedUser, mutate, query
|
let authenticatedUser, user, mutate, query
|
||||||
const reportMutation = gql`
|
const reportMutation = gql`
|
||||||
mutation($resourceId: ID!, $reasonCategory: ReasonCategory!, $reasonDescription: String!) {
|
mutation($resourceId: ID!, $reasonCategory: ReasonCategory!, $reasonDescription: String!) {
|
||||||
report(
|
report(
|
||||||
@ -35,39 +35,89 @@ describe('report',()=>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
const variables = {
|
const variables = {
|
||||||
resourceId: 'whatever',
|
resourceId: 'whatever',
|
||||||
reasonCategory: 'other',
|
reasonCategory: 'other',
|
||||||
reasonDescription: 'Violates code of conduct !!!',
|
reasonDescription: 'Violates code of conduct !!!',
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeAll(()=>{
|
beforeAll(() => {
|
||||||
const {server} = createServer({
|
const { server } = createServer({
|
||||||
context: ()=>{
|
context: () => {
|
||||||
return {
|
return {
|
||||||
driver,
|
driver,
|
||||||
neode: instance,
|
neode: instance,
|
||||||
user: authenticatedUser
|
user: authenticatedUser,
|
||||||
}
|
}
|
||||||
|
},
|
||||||
}
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
mutate = createTestClient(server).mutate
|
mutate = createTestClient(server).mutate
|
||||||
query = createTestClient(server).query
|
query = createTestClient(server).query
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(async()=>{
|
afterEach(async () => {
|
||||||
await factory.cleanDatabase()
|
await factory.cleanDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('create report', ()=>{
|
describe('create report', () => {
|
||||||
describe('unauthenticated',()=>{
|
describe('unauthenticated', () => {
|
||||||
it.only('throws authorization error', async() =>{
|
it('throws authorization error', async () => {
|
||||||
await expect(mutate({mutation: reportMutation, variables})).resolves.toMatchObject({
|
authenticatedUser = null
|
||||||
data: {report: null},
|
await expect(mutate({ mutation: reportMutation, variables })).resolves.toMatchObject({
|
||||||
errors: [{message: 'Not Authorised!'}]
|
data: { report: null },
|
||||||
|
errors: [{ message: 'Not Authorised!' }],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('authenticated', () => {
|
||||||
|
const categoryIds = ['cat9']
|
||||||
|
beforeEach(async () => {
|
||||||
|
user = await factory.create('User', {
|
||||||
|
id: 'u1',
|
||||||
|
role: 'user',
|
||||||
|
email: 'test@example.org',
|
||||||
|
password: '1234',
|
||||||
|
})
|
||||||
|
await factory.create('User', {
|
||||||
|
id: 'abusive-user-id',
|
||||||
|
role: 'user',
|
||||||
|
name: 'abusive-user',
|
||||||
|
email: 'abusive-user@example.org',
|
||||||
|
})
|
||||||
|
await instance.create('Category', {
|
||||||
|
id: 'cat9',
|
||||||
|
name: 'Democracy & Politics',
|
||||||
|
icon: 'university',
|
||||||
|
})
|
||||||
|
|
||||||
|
authenticatedUser = await user.toJson()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('invalid resource id', () => {
|
||||||
|
it('returns null', async () => {
|
||||||
|
await expect(mutate({ mutation: reportMutation, variables })).resolves.toMatchObject({
|
||||||
|
data: { report: null },
|
||||||
|
errors: undefined,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('valid resource', () => {
|
||||||
|
describe('reported resource is a user', () => {
|
||||||
|
it('returns type "User"', async () => {
|
||||||
|
await expect(
|
||||||
|
mutate({ mutation: reportMutation, variables: { ...variables, resourceId: 'abusive-user-id' } }),
|
||||||
|
).resolves.toMatchObject({
|
||||||
|
data: {
|
||||||
|
report: {
|
||||||
|
type: 'User',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
errors: undefined,
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -83,107 +133,10 @@ const variables = {
|
|||||||
// let user
|
// let user
|
||||||
// const categoryIds = ['cat9']
|
// const categoryIds = ['cat9']
|
||||||
|
|
||||||
// const action = () => {
|
|
||||||
// reportMutation = gql`
|
|
||||||
// mutation($resourceId: ID!, $reasonCategory: ReasonCategory!, $reasonDescription: String!) {
|
|
||||||
// report(
|
|
||||||
// resourceId: $resourceId
|
|
||||||
// reasonCategory: $reasonCategory
|
|
||||||
// reasonDescription: $reasonDescription
|
|
||||||
// ) {
|
|
||||||
// createdAt
|
|
||||||
// reasonCategory
|
|
||||||
// reasonDescription
|
|
||||||
// type
|
|
||||||
// submitter {
|
|
||||||
// email
|
|
||||||
// }
|
|
||||||
// user {
|
|
||||||
// name
|
|
||||||
// }
|
|
||||||
// post {
|
|
||||||
// title
|
|
||||||
// }
|
|
||||||
// comment {
|
|
||||||
// content
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// `
|
|
||||||
// client = new GraphQLClient(host, {
|
|
||||||
// headers,
|
|
||||||
// })
|
|
||||||
// return client.request(reportMutation, variables)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// beforeEach(async () => {
|
|
||||||
// variables = {
|
|
||||||
// resourceId: 'whatever',
|
|
||||||
// reasonCategory: 'other',
|
|
||||||
// reasonDescription: 'Violates code of conduct !!!',
|
|
||||||
// }
|
|
||||||
// headers = {}
|
|
||||||
// user = await factory.create('User', {
|
|
||||||
// id: 'u1',
|
|
||||||
// role: 'user',
|
|
||||||
// email: 'test@example.org',
|
|
||||||
// password: '1234',
|
|
||||||
// })
|
|
||||||
// await factory.create('User', {
|
|
||||||
// id: 'u2',
|
|
||||||
// role: 'user',
|
|
||||||
// name: 'abusive-user',
|
|
||||||
// email: 'abusive-user@example.org',
|
|
||||||
// })
|
|
||||||
// await instance.create('Category', {
|
|
||||||
// id: 'cat9',
|
|
||||||
// name: 'Democracy & Politics',
|
|
||||||
// icon: 'university',
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
|
|
||||||
// afterEach(async () => {
|
|
||||||
// await factory.cleanDatabase()
|
|
||||||
// })
|
|
||||||
|
|
||||||
// describe('unauthenticated', () => {
|
|
||||||
// it('throws authorization error', async () => {
|
|
||||||
// await expect(action()).rejects.toThrow('Not Authorised')
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
|
|
||||||
// describe('authenticated', () => {
|
// describe('authenticated', () => {
|
||||||
// beforeEach(async () => {
|
|
||||||
// headers = await login({
|
|
||||||
// email: 'test@example.org',
|
|
||||||
// password: '1234',
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
|
|
||||||
// describe('invalid resource id', () => {
|
|
||||||
// it('returns null', async () => {
|
|
||||||
// await expect(action()).resolves.toEqual({
|
|
||||||
// report: null,
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
|
|
||||||
// describe('valid resource id', () => {
|
// describe('valid resource id', () => {
|
||||||
// describe('reported resource is a user', () => {
|
// describe('reported resource is a user', () => {
|
||||||
// beforeEach(async () => {
|
|
||||||
// variables = {
|
|
||||||
// ...variables,
|
|
||||||
// resourceId: 'u2',
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
// it('returns type "User"', async () => {
|
|
||||||
// await expect(action()).resolves.toMatchObject({
|
|
||||||
// report: {
|
|
||||||
// type: 'User',
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
|
|
||||||
// it('returns resource in user attribute', async () => {
|
// it('returns resource in user attribute', async () => {
|
||||||
// await expect(action()).resolves.toMatchObject({
|
// await expect(action()).resolves.toMatchObject({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user