Skip to content

Commit

Permalink
Merge branch 'staging' into feat/table-for-lti-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
hejtful committed Jul 11, 2024
2 parents f98baa2 + 460918a commit f3ec2f2
Show file tree
Hide file tree
Showing 45 changed files with 628 additions and 890 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion __fixtures__/uuid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export * from './course-page'
export * from './exercise'
export * from './exercise-group'
export * from './event'
export * from './page'
export * from './taxonomy-term'
export * from './thread'
export * from './user'
Expand Down
41 changes: 0 additions & 41 deletions __fixtures__/uuid/page.ts

This file was deleted.

9 changes: 9 additions & 0 deletions __tests__/schema/entity/checkout-revision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ test('checks out a revision', async () => {
})
})

test('allows to checkout a revision for pages for static pages builder', async () => {
const newMutation = await mutation
.changeInput({ revisionId: 35476 })
.forUser('de_static_pages_builder')
await newMutation.shouldReturnData({
entity: { checkoutRevision: { success: true } },
})
})

test('checkout revision has trashed == false for following queries', async () => {
await databaseForTests.mutate('update uuid set trashed = 1 where id = ?', [
input.revisionId,
Expand Down
13 changes: 13 additions & 0 deletions __tests__/schema/entity/set-abstract-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ test('creates a new entity when "parentId" is set', async () => {
)
})

test('creates a new entity when "parentId" is set (for static pages)', async () => {
const newMutation = await mutation
.changeInput({
parentId: 282309,
entityType: 'Page',
})
.forUser('de_static_pages_builder')

await newMutation.shouldReturnData({
entity: { setAbstractEntity: { success: true } },
})
})

test('creates a subscription', async () => {
await subscriptionsQuery.withContext({ userId: 15491 }).shouldReturnData({
subscription: { getSubscriptions: { nodes: [] } },
Expand Down
151 changes: 20 additions & 131 deletions __tests__/schema/page/add-revision.ts
Original file line number Diff line number Diff line change
@@ -1,140 +1,29 @@
import gql from 'graphql-tag'
import { HttpResponse } from 'msw'
import * as R from 'ramda'

import { page, pageRevision, user as baseUser } from '../../../__fixtures__'
import { given, Client, nextUuid } from '../../__utils__'
import { Client } from '../../__utils__'

const user = { ...baseUser, roles: ['de_static_pages_builder'] }
const input = {
content: 'new content',
title: 'new title',
pageId: 19767,
}

describe('PageAddRevisionMutation', () => {
const input = {
content: 'new content',
title: 'new title',
pageId: page.id,
}

const mutation = new Client({ userId: user.id })
.prepareQuery({
query: gql`
mutation set($input: PageAddRevisionInput!) {
page {
addRevision(input: $input) {
success
}
}
const mutation = new Client().prepareQuery({
query: gql`
mutation set($input: PageAddRevisionInput!) {
page {
addRevision(input: $input) {
success
}
`,
})
.withVariables({ input })

const newRevisionId = nextUuid(pageRevision.id)

beforeEach(() => {
given('UuidQuery').for(user, page, pageRevision)
given('PageAddRevisionMutation').isDefinedBy(async ({ request }) => {
const body = await request.json()
// const { title, content } = req.body.payload
const newRevision = {
...pageRevision,
...R.pick(['title', 'content'], body.payload),
id: newRevisionId,
}
given('UuidQuery').for(newRevision)
given('UuidQuery').for({
...page,
revisionIds: [newRevision.id, ...page.revisionIds],
currentRevisionId: newRevision.id,
})
return HttpResponse.json({ success: true, revisionId: newRevision.id })
})
})

test('returns "{ success: true }" when mutation could be successfully executed', async () => {
await mutation.shouldReturnData({
page: { addRevision: { success: true } },
})
})

test('updates the cache', async () => {
const query = new Client({ userId: user.id })
.prepareQuery({
query: gql`
query ($id: Int!) {
uuid(id: $id) {
... on Page {
currentRevision {
id
content
title
}
}
}
}
`,
})
.withVariables({ id: page.id })

await query.shouldReturnData({
uuid: {
currentRevision: {
id: pageRevision.id,
content: pageRevision.content,
title: pageRevision.title,
},
},
})

await mutation.execute()

await query.shouldReturnData({
uuid: {
currentRevision: {
id: newRevisionId,
content: input.content,
title: input.title,
},
},
})
})

test('fails when user is not authenticated', async () => {
await mutation
.forUnauthenticatedUser()
.shouldFailWithError('UNAUTHENTICATED')
})

test('fails when user does not have role "static_pages_builder"', async () => {
await mutation.forLoginUser().shouldFailWithError('FORBIDDEN')
})

test('fails when `title` or `content` is empty', async () => {
await mutation
.withInput({
content: '',
title: 'title',
pageId: page.id,
})
.shouldFailWithError('BAD_USER_INPUT')

await mutation
.withInput({
content: 'content',
title: '',
pageId: page.id,
})
.shouldFailWithError('BAD_USER_INPUT')
})

test('fails when database layer returns a 400er response', async () => {
given('PageAddRevisionMutation').returnsBadRequest()

await mutation.shouldFailWithError('BAD_USER_INPUT')
})

test('fails when database layer has an internal error', async () => {
given('PageAddRevisionMutation').hasInternalServerError()
}
`,
variables: { input },
})

await mutation.shouldFailWithError('INTERNAL_SERVER_ERROR')
test('returns "{ success: true }" when mutation could be successfully executed', async () => {
const newMutation = await mutation.forUser('de_static_pages_builder')
await newMutation.shouldReturnData({
page: { addRevision: { success: true } },
})
})
121 changes: 5 additions & 116 deletions __tests__/schema/page/checkout-revision.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
import gql from 'graphql-tag'
import { HttpResponse } from 'msw'

import {
page as basePage,
pageRevision,
user as baseUser,
} from '../../../__fixtures__'
import { given, nextUuid, Client } from '../../__utils__'
import { Instance } from '~/types'
import { Client } from '../../__utils__'

const user = { ...baseUser, roles: ['de_static_pages_builder'] }
const page = {
...basePage,
instance: Instance.De,
currentRevision: pageRevision.id,
}
const unrevisedRevision = {
...pageRevision,
id: nextUuid(pageRevision.id),
trashed: true,
}
const mutation = new Client({ userId: user.id })
const mutation = new Client()
.prepareQuery({
query: gql`
mutation ($input: CheckoutRevisionInput!) {
Expand All @@ -32,104 +14,11 @@ const mutation = new Client({ userId: user.id })
}
`,
})
.withInput({ revisionId: unrevisedRevision.id, reason: 'reason' })

beforeEach(() => {
given('UuidQuery').for(user, page, pageRevision, unrevisedRevision)
given('PageCheckoutRevisionMutation')
.withPayload({
userId: user.id,
reason: 'reason',
revisionId: unrevisedRevision.id,
})
.isDefinedBy(() => {
given('UuidQuery').for({
...page,
currentRevisionId: unrevisedRevision.id,
})
given('UuidQuery').for({ ...unrevisedRevision, trashed: false })

return HttpResponse.json({ success: true })
})
})
.withInput({ revisionId: 35476, reason: 'reason' })

test('returns "{ success: true }" when mutation could be successfully executed', async () => {
await mutation.shouldReturnData({
const newMutation = await mutation.forUser('de_static_pages_builder')
await newMutation.shouldReturnData({
page: { checkoutRevision: { success: true } },
})
})

test('following queries for page point to checkout revision when page is already in the cache', async () => {
const pageQuery = new Client()
.prepareQuery({
query: gql`
query ($id: Int!) {
uuid(id: $id) {
... on Page {
currentRevision {
id
}
}
}
}
`,
})
.withVariables({ id: page.id })

await pageQuery.shouldReturnData({
uuid: { currentRevision: { id: pageRevision.id } },
})

await mutation.shouldReturnData({
page: { checkoutRevision: { success: true } },
})

await pageQuery.shouldReturnData({
uuid: { currentRevision: { id: unrevisedRevision.id } },
})
})

test('checkout revision has trashed == false for following queries', async () => {
const revisionQuery = new Client()
.prepareQuery({
query: gql`
query ($id: Int!) {
uuid(id: $id) {
... on PageRevision {
trashed
}
}
}
`,
})
.withVariables({ id: unrevisedRevision.id })

await revisionQuery.shouldReturnData({ uuid: { trashed: true } })

await mutation.shouldReturnData({
page: { checkoutRevision: { success: true } },
})

await revisionQuery.shouldReturnData({ uuid: { trashed: false } })
})

test('fails when user is not authenticated', async () => {
await mutation.forUnauthenticatedUser().shouldFailWithError('UNAUTHENTICATED')
})

test('fails when user does not have role "static_pages_builder"', async () => {
const newMutation = await mutation.forUser('de_moderator')
await newMutation.shouldFailWithError('FORBIDDEN')
})

test('fails when database layer returns a 400er response', async () => {
given('PageCheckoutRevisionMutation').returnsBadRequest()

await mutation.shouldFailWithError('BAD_USER_INPUT')
})

test('fails when database layer has an internal error', async () => {
given('PageCheckoutRevisionMutation').hasInternalServerError()

await mutation.shouldFailWithError('INTERNAL_SERVER_ERROR')
})
Loading

0 comments on commit f3ec2f2

Please sign in to comment.