mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
First Vue design of delete SocialMedia, custom mutation DeleteSocialMedia
Backend Jest tests for DeleteSocialMedia New backend Jest tests for CreateSocialMedia
This commit is contained in:
parent
a4f5fdc324
commit
b03cbb212a
@ -75,6 +75,7 @@ const permissions = shield({
|
|||||||
DeleteBadge: isAdmin,
|
DeleteBadge: isAdmin,
|
||||||
AddUserBadges: isAdmin,
|
AddUserBadges: isAdmin,
|
||||||
CreateSocialMedia: isAuthenticated,
|
CreateSocialMedia: isAuthenticated,
|
||||||
|
DeleteSocialMedia: isAuthenticated,
|
||||||
// AddBadgeRewarded: isAdmin,
|
// AddBadgeRewarded: isAdmin,
|
||||||
// RemoveBadgeRewarded: isAdmin,
|
// RemoveBadgeRewarded: isAdmin,
|
||||||
reward: isAdmin,
|
reward: isAdmin,
|
||||||
|
|||||||
@ -3,6 +3,9 @@ import { neo4jgraphql } from 'neo4j-graphql-js'
|
|||||||
export default {
|
export default {
|
||||||
Mutation: {
|
Mutation: {
|
||||||
CreateSocialMedia: async (object, params, context, resolveInfo) => {
|
CreateSocialMedia: async (object, params, context, resolveInfo) => {
|
||||||
|
/**
|
||||||
|
* TODO?: Creates double Nodes!
|
||||||
|
*/
|
||||||
const socialMedia = await neo4jgraphql(object, params, context, resolveInfo, false)
|
const socialMedia = await neo4jgraphql(object, params, context, resolveInfo, false)
|
||||||
const session = context.driver.session()
|
const session = context.driver.session()
|
||||||
await session.run(
|
await session.run(
|
||||||
@ -15,6 +18,11 @@ export default {
|
|||||||
)
|
)
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
|
return socialMedia
|
||||||
|
},
|
||||||
|
DeleteSocialMedia: async (object, params, context, resolveInfo) => {
|
||||||
|
const socialMedia = await neo4jgraphql(object, params, context, resolveInfo, false)
|
||||||
|
|
||||||
return socialMedia
|
return socialMedia
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,9 +7,18 @@ const factory = Factory()
|
|||||||
describe('CreateSocialMedia', () => {
|
describe('CreateSocialMedia', () => {
|
||||||
let client
|
let client
|
||||||
let headers
|
let headers
|
||||||
const mutation = `
|
const mutationC = `
|
||||||
mutation($url: String!) {
|
mutation($url: String!) {
|
||||||
CreateSocialMedia(url: $url) {
|
CreateSocialMedia(url: $url) {
|
||||||
|
id
|
||||||
|
url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
const mutationD = `
|
||||||
|
mutation($id: ID!) {
|
||||||
|
DeleteSocialMedia(id: $id) {
|
||||||
|
id
|
||||||
url
|
url
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -30,20 +39,63 @@ describe('CreateSocialMedia', () => {
|
|||||||
await factory.cleanDatabase()
|
await factory.cleanDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('unauthenticated', () => {
|
||||||
|
it('throws authorization error', async () => {
|
||||||
|
client = new GraphQLClient(host)
|
||||||
|
const variables = { url: 'http://nsosp.org' }
|
||||||
|
await expect(
|
||||||
|
client.request(mutationC, variables)
|
||||||
|
).rejects.toThrow('Not Authorised')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('authenticated', () => {
|
describe('authenticated', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
headers = await login({ email: 'test@example.org', password: '1234' })
|
headers = await login({ email: 'test@example.org', password: '1234' })
|
||||||
client = new GraphQLClient(host, { headers })
|
client = new GraphQLClient(host, { headers })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('creates social media with correct URL', async () => {
|
||||||
|
const variables = { url: 'http://nsosp.org' }
|
||||||
|
await expect(
|
||||||
|
client.request(mutationC, variables)
|
||||||
|
).resolves.toEqual(expect.objectContaining({
|
||||||
|
CreateSocialMedia: {
|
||||||
|
id: expect.any(String),
|
||||||
|
url: 'http://nsosp.org'
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('deletes social media', async () => {
|
||||||
|
const variablesC = { url: 'http://nsosp.org' }
|
||||||
|
const { CreateSocialMedia } = await client.request(mutationC, variablesC)
|
||||||
|
const { id } = CreateSocialMedia
|
||||||
|
|
||||||
|
const variablesD = { id }
|
||||||
|
const expected = {
|
||||||
|
DeleteSocialMedia: {
|
||||||
|
id: id,
|
||||||
|
url: 'http://nsosp.org'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await expect(
|
||||||
|
client.request(mutationD, variablesD)
|
||||||
|
).resolves.toEqual(expected)
|
||||||
|
})
|
||||||
|
|
||||||
it('rejects empty string', async () => {
|
it('rejects empty string', async () => {
|
||||||
const variables = { url: '' }
|
const variables = { url: '' }
|
||||||
await expect(client.request(mutation, variables)).rejects.toThrow('Input is not a URL')
|
await expect(
|
||||||
|
client.request(mutationC, variables)
|
||||||
|
).rejects.toThrow('Input is not a URL')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('validates URLs', async () => {
|
it('validates URLs', async () => {
|
||||||
const variables = { url: 'not-a-url' }
|
const variables = { url: 'not-a-url' }
|
||||||
await expect(client.request(mutation, variables)).rejects.toThrow('Input is not a URL')
|
await expect(
|
||||||
|
client.request(mutationC, variables)
|
||||||
|
).rejects.toThrow('Input is not a URL')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -22,26 +22,38 @@
|
|||||||
>
|
>
|
||||||
{{ link.url }}
|
{{ link.url }}
|
||||||
</a>
|
</a>
|
||||||
|
|
|
||||||
|
<ds-icon
|
||||||
|
name="edit"
|
||||||
|
class="layout-leave-active"
|
||||||
|
/>
|
||||||
|
<a
|
||||||
|
@click="onDelete(link)"
|
||||||
|
>
|
||||||
|
<ds-icon name="trash"/>
|
||||||
|
</a>
|
||||||
</ds-list-item>
|
</ds-list-item>
|
||||||
</ds-list>
|
</ds-list>
|
||||||
</ds-space>
|
</ds-space>
|
||||||
<div>
|
|
||||||
<ds-input
|
|
||||||
v-model="value"
|
|
||||||
placeholder="Add social media url"
|
|
||||||
name="social-media"
|
|
||||||
:schema="{type: 'url'}"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<ds-space margin-top="base">
|
<ds-space margin-top="base">
|
||||||
<div>
|
<div>
|
||||||
<ds-button
|
<ds-input
|
||||||
primary
|
v-model="value"
|
||||||
@click="handleAddSocialMedia"
|
placeholder="Add social media url"
|
||||||
>
|
name="social-media"
|
||||||
{{ $t('settings.social-media.submit') }}
|
:schema="{type: 'url'}"
|
||||||
</ds-button>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<ds-space margin-top="base">
|
||||||
|
<div>
|
||||||
|
<ds-button
|
||||||
|
primary
|
||||||
|
@click="handleAddSocialMedia"
|
||||||
|
>
|
||||||
|
{{ $t('settings.social-media.submit') }}
|
||||||
|
</ds-button>
|
||||||
|
</div>
|
||||||
|
</ds-space>
|
||||||
</ds-space>
|
</ds-space>
|
||||||
</ds-card>
|
</ds-card>
|
||||||
</template>
|
</template>
|
||||||
@ -104,7 +116,16 @@ export default {
|
|||||||
this.$toast.success(this.$t('settings.social-media.success')),
|
this.$toast.success(this.$t('settings.social-media.success')),
|
||||||
(this.value = '')
|
(this.value = '')
|
||||||
)
|
)
|
||||||
|
},
|
||||||
|
onDelete(link) {
|
||||||
|
console.log(link)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.layout-leave-active {
|
||||||
|
opacity: 0.4;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user