mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
tests
This commit is contained in:
parent
96e027ae0a
commit
52b582e54d
@ -592,6 +592,207 @@ describe('switch user role', () => {
|
||||
})
|
||||
})
|
||||
|
||||
let anotherUser
|
||||
const emailNotificationSettingsQuery = gql`
|
||||
query ($id: ID!) {
|
||||
User(id: $id) {
|
||||
emailNotificationSettings {
|
||||
type
|
||||
settings {
|
||||
name
|
||||
value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const emailNotificationSettingsMutation = gql`
|
||||
mutation ($id: ID!, $emailNotificationSettings: [emailNotificationSettings]!) {
|
||||
UpdateUser(id: $id, emailNotificationSettings: $emailNotificationSettings) {
|
||||
emailNotificationSettings {
|
||||
type
|
||||
settings {
|
||||
name
|
||||
value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
describe('emailNotificationSettings', () => {
|
||||
beforeEach(async () => {
|
||||
user = await Factory.build('user', {
|
||||
id: 'user',
|
||||
role: 'user',
|
||||
})
|
||||
anotherUser = await Factory.build('user', {
|
||||
id: 'anotherUser',
|
||||
role: 'anotherUser',
|
||||
})
|
||||
})
|
||||
|
||||
describe('query the field', () => {
|
||||
describe('as another user', () => {
|
||||
it('throws an error', async () => {
|
||||
authenticatedUser = await anotherUser.toJson()
|
||||
const targetUser = await user.toJson()
|
||||
await expect(
|
||||
query({ query: emailNotificationSettingsQuery, variables: { id: targetUser.id } }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [
|
||||
expect.objectContaining({
|
||||
message: 'Not Authorized!',
|
||||
}),
|
||||
],
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('as self', () => {
|
||||
it('returns the emailNotificationSettings', async () => {
|
||||
authenticatedUser = await user.toJson()
|
||||
await expect(
|
||||
query({ query: emailNotificationSettingsQuery, variables: { id: authenticatedUser.id } }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
data: {
|
||||
User: [
|
||||
{
|
||||
emailNotificationSettings: [
|
||||
{
|
||||
type: 'post',
|
||||
settings: [
|
||||
{
|
||||
name: 'commentOnObservedPost',
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: 'mention',
|
||||
value: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'group',
|
||||
settings: [
|
||||
{
|
||||
name: 'groupMemberJoined',
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: 'groupMemberLeft',
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: 'groupMemberRemoved',
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: 'groupMemberRoleChanged',
|
||||
value: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('mutate the field', () => {
|
||||
const emailNotificationSettings = [
|
||||
{ name: 'mention', value: false },
|
||||
{ name: 'non-existent', value: true },
|
||||
]
|
||||
|
||||
describe('as another user', () => {
|
||||
it('throws an error', async () => {
|
||||
authenticatedUser = await anotherUser.toJson()
|
||||
const targetUser = await user.toJson()
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: emailNotificationSettingsMutation,
|
||||
variables: { id: targetUser.id, emailNotificationSettings },
|
||||
}),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [
|
||||
expect.objectContaining({
|
||||
message: 'Not Authorized!',
|
||||
}),
|
||||
],
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('as self', () => {
|
||||
it('returns the emailNotificationSettings', async () => {
|
||||
authenticatedUser = await user.toJson()
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: emailNotificationSettingsMutation,
|
||||
variables: { id: authenticatedUser.id, emailNotificationSettings },
|
||||
}),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
data: {
|
||||
User: [
|
||||
{
|
||||
emailNotificationSettings: [
|
||||
{
|
||||
type: 'post',
|
||||
settings: [
|
||||
{
|
||||
name: 'commentOnObservedPost',
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: 'mention',
|
||||
value: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'group',
|
||||
settings: [
|
||||
{
|
||||
name: 'groupMemberJoined',
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: 'groupMemberLeft',
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: 'groupMemberRemoved',
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
name: 'groupMemberRoleChanged',
|
||||
value: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('save category settings', () => {
|
||||
beforeEach(async () => {
|
||||
await Promise.all(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user