feat: add guilds and channels CRUD (#14)
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
import { channelExample } from '../../../fixtures/channels/channel'
|
||||
import { guildExample } from '../../../fixtures/guilds/guild'
|
||||
import { userExample } from '../../../fixtures/users/user'
|
||||
import { getGuildsHandler } from '../../../fixtures/guilds/get'
|
||||
import { authenticationHandlers } from '../../../fixtures/handler'
|
||||
import { getGuildMemberWithGuildIdHandler } from '../../../fixtures/guilds/[guildId]/get'
|
||||
import { getChannelWithChannelIdHandler } from '../../../fixtures/channels/[channelId]/get'
|
||||
@ -10,9 +9,13 @@ import { getUserByIdHandler } from '../../../fixtures/users/[userId]/get'
|
||||
const applicationPaths = [
|
||||
'/application',
|
||||
`/application/users/${userExample.id}`,
|
||||
`/application/users/settings`,
|
||||
'/application/guilds/create',
|
||||
'/application/guilds/join',
|
||||
`/application/${guildExample.id}/${channelExample.id}`
|
||||
`/application/${guildExample.id}/${channelExample.id}`,
|
||||
`/application/${guildExample.id}/${channelExample.id}/settings`,
|
||||
`/application/${guildExample.id}/channels/create`,
|
||||
`/application/${guildExample.id}/settings`
|
||||
]
|
||||
|
||||
describe('Common > application/authentication', () => {
|
||||
@ -31,7 +34,6 @@ describe('Common > application/authentication', () => {
|
||||
it('should not redirect the user if signed in', () => {
|
||||
cy.task('startMockServer', [
|
||||
...authenticationHandlers,
|
||||
getGuildsHandler,
|
||||
getGuildMemberWithGuildIdHandler,
|
||||
getChannelWithChannelIdHandler,
|
||||
getUserByIdHandler
|
||||
|
@ -3,34 +3,37 @@ import date from 'date-and-time'
|
||||
import {
|
||||
channelExample,
|
||||
channelExample2
|
||||
} from '../../../../fixtures/channels/channel'
|
||||
import { guildExample } from '../../../../fixtures/guilds/guild'
|
||||
import { getGuildMemberWithGuildIdHandler } from '../../../../fixtures/guilds/[guildId]/get'
|
||||
import { getChannelWithChannelIdHandler } from '../../../../fixtures/channels/[channelId]/get'
|
||||
import { authenticationHandlers } from '../../../../fixtures/handler'
|
||||
import { getGuildsHandler } from '../../../../fixtures/guilds/get'
|
||||
import { getChannelsWithGuildIdHandler } from '../../../../fixtures/guilds/[guildId]/channels/get'
|
||||
import { getMessagesWithChannelIdHandler } from '../../../../fixtures/channels/[channelId]/messages/get'
|
||||
} from '../../../../../fixtures/channels/channel'
|
||||
import { guildExample } from '../../../../../fixtures/guilds/guild'
|
||||
import {
|
||||
getGuildMemberNotOwnerWithGuildIdHandler,
|
||||
getGuildMemberWithGuildIdHandler
|
||||
} from '../../../../../fixtures/guilds/[guildId]/get'
|
||||
import { getChannelWithChannelIdHandler } from '../../../../../fixtures/channels/[channelId]/get'
|
||||
import { authenticationHandlers } from '../../../../../fixtures/handler'
|
||||
import { getGuildsHandler } from '../../../../../fixtures/guilds/get'
|
||||
import { getChannelsWithGuildIdHandler } from '../../../../../fixtures/guilds/[guildId]/channels/get'
|
||||
import { getMessagesWithChannelIdHandler } from '../../../../../fixtures/channels/[channelId]/messages/get'
|
||||
import {
|
||||
messageExampleComplete,
|
||||
messageExampleComplete2
|
||||
} from '../../../../fixtures/messages/message'
|
||||
import { getMembersWithGuildIdHandler } from '../../../../fixtures/guilds/[guildId]/members/get'
|
||||
import { memberExampleComplete } from '../../../../fixtures/members/member'
|
||||
import { API_URL } from '../../../../../tools/api'
|
||||
} from '../../../../../fixtures/messages/message'
|
||||
import { getMembersWithGuildIdHandler } from '../../../../../fixtures/guilds/[guildId]/members/get'
|
||||
import { memberExampleComplete } from '../../../../../fixtures/members/member'
|
||||
import { API_URL } from '../../../../../../tools/api'
|
||||
import {
|
||||
getMessagesUploadsAudioHandler,
|
||||
getMessagesUploadsDownloadHandler,
|
||||
getMessagesUploadsImageHandler,
|
||||
getMessagesUploadsVideoHandler
|
||||
} from '../../../../fixtures/uploads/messages/get'
|
||||
} from '../../../../../fixtures/uploads/messages/get'
|
||||
|
||||
describe('Pages > /application/[guildId]/[channelId]', () => {
|
||||
beforeEach(() => {
|
||||
cy.task('stopMockServer')
|
||||
})
|
||||
|
||||
it('should succeeds and display the guilds in left sidebar correctly', () => {
|
||||
it('should succeeds and display the left sidebar correctly (member is owner)', () => {
|
||||
cy.task('startMockServer', [
|
||||
...authenticationHandlers,
|
||||
getGuildMemberWithGuildIdHandler,
|
||||
@ -50,6 +53,43 @@ describe('Pages > /application/[guildId]/[channelId]', () => {
|
||||
guildExample.name
|
||||
)
|
||||
cy.get('.guilds-list').children().should('have.length', 2)
|
||||
cy.get('[data-cy=link-add-channel]')
|
||||
.should('be.visible')
|
||||
.should(
|
||||
'have.attr',
|
||||
'href',
|
||||
`/application/${guildExample.id}/channels/create`
|
||||
)
|
||||
cy.get('[data-cy=link-settings-guild]')
|
||||
.should('be.visible')
|
||||
.should('have.attr', 'href', `/application/${guildExample.id}/settings`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should succeeds and display the left sidebar correctly (member is not owner)', () => {
|
||||
cy.task('startMockServer', [
|
||||
...authenticationHandlers,
|
||||
getGuildMemberNotOwnerWithGuildIdHandler,
|
||||
getChannelWithChannelIdHandler,
|
||||
getGuildsHandler
|
||||
]).setCookie('refreshToken', 'refresh-token')
|
||||
cy.intercept(`${API_URL}${getGuildsHandler.url}*`).as('getGuildsHandler')
|
||||
cy.intercept(`/_next/*`).as('nextStaticAndImages')
|
||||
cy.visit(`/application/${guildExample.id}/${channelExample.id}`)
|
||||
cy.wait(['@getGuildsHandler', '@nextStaticAndImages']).then(() => {
|
||||
cy.get('[data-cy=application-title]').should(
|
||||
'have.text',
|
||||
`# ${channelExample.name}`
|
||||
)
|
||||
cy.get('[data-cy=guild-left-sidebar-title]').should(
|
||||
'have.text',
|
||||
guildExample.name
|
||||
)
|
||||
cy.get('.guilds-list').children().should('have.length', 2)
|
||||
cy.get('[data-cy=link-add-channel]').should('not.exist')
|
||||
cy.get('[data-cy=link-settings-guild]')
|
||||
.should('be.visible')
|
||||
.should('have.attr', 'href', `/application/${guildExample.id}/settings`)
|
||||
})
|
||||
})
|
||||
|
@ -0,0 +1,133 @@
|
||||
import { deleteChannelWithChannelIdHandler } from '../../../../../fixtures/channels/[channelId]/delete'
|
||||
import { putChannelWithChannelIdHandler } from '../../../../../fixtures/channels/[channelId]/put'
|
||||
import {
|
||||
channelExample,
|
||||
channelExample2
|
||||
} from '../../../../../fixtures/channels/channel'
|
||||
import { guildExample } from '../../../../../fixtures/guilds/guild'
|
||||
import {
|
||||
getGuildMemberNotOwnerWithGuildIdHandler,
|
||||
getGuildMemberWithGuildIdHandler
|
||||
} from '../../../../../fixtures/guilds/[guildId]/get'
|
||||
import {
|
||||
getChannelWithChannelIdHandler,
|
||||
getChannelWithChannelIdHandler2
|
||||
} from '../../../../../fixtures/channels/[channelId]/get'
|
||||
import { authenticationHandlers } from '../../../../../fixtures/handler'
|
||||
import { API_URL } from '../../../../../../tools/api'
|
||||
|
||||
describe('Pages > /application/[guildId]/[channelId]/settings', () => {
|
||||
beforeEach(() => {
|
||||
cy.task('stopMockServer')
|
||||
})
|
||||
|
||||
it('should succeeds and update the channel name', () => {
|
||||
cy.task('startMockServer', [
|
||||
...authenticationHandlers,
|
||||
getGuildMemberWithGuildIdHandler,
|
||||
getChannelWithChannelIdHandler,
|
||||
putChannelWithChannelIdHandler
|
||||
]).setCookie('refreshToken', 'refresh-token')
|
||||
cy.intercept(`${API_URL}${putChannelWithChannelIdHandler.url}*`).as(
|
||||
'putChannelWithChannelIdHandler'
|
||||
)
|
||||
cy.visit(`/application/${guildExample.id}/${channelExample.id}/settings`)
|
||||
cy.get('[data-cy=channel-name-input]')
|
||||
.clear()
|
||||
.type(putChannelWithChannelIdHandler.response.body.name)
|
||||
cy.get('[data-cy=button-save-channel-settings]').click()
|
||||
cy.wait('@putChannelWithChannelIdHandler').then(() => {
|
||||
cy.location('pathname').should(
|
||||
'eq',
|
||||
`/application/${guildExample.id}/${channelExample.id}`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it('should succeeds and delete the channel', () => {
|
||||
cy.task('startMockServer', [
|
||||
...authenticationHandlers,
|
||||
getGuildMemberWithGuildIdHandler,
|
||||
getChannelWithChannelIdHandler,
|
||||
getChannelWithChannelIdHandler2,
|
||||
deleteChannelWithChannelIdHandler
|
||||
]).setCookie('refreshToken', 'refresh-token')
|
||||
cy.intercept(`${API_URL}${deleteChannelWithChannelIdHandler.url}*`).as(
|
||||
'deleteChannelWithChannelIdHandler'
|
||||
)
|
||||
cy.visit(`/application/${guildExample.id}/${channelExample.id}/settings`)
|
||||
cy.get('[data-cy=button-delete-channel-settings]').click()
|
||||
cy.wait('@deleteChannelWithChannelIdHandler').then(() => {
|
||||
cy.location('pathname').should(
|
||||
'eq',
|
||||
`/application/${guildExample.id}/${channelExample2.id}`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it('should fails with too long channel name on update', () => {
|
||||
cy.task('startMockServer', [
|
||||
...authenticationHandlers,
|
||||
getGuildMemberWithGuildIdHandler,
|
||||
getChannelWithChannelIdHandler
|
||||
]).setCookie('refreshToken', 'refresh-token')
|
||||
cy.visit(`/application/${guildExample.id}/${channelExample.id}/settings`)
|
||||
cy.get('[data-cy=channel-name-input]').type(
|
||||
'random channel name that is really too long for a channel name'
|
||||
)
|
||||
cy.get('[data-cy=button-save-channel-settings]').click()
|
||||
cy.get('#error-name').should(
|
||||
'have.text',
|
||||
'Error: The field must contain at most 20 characters.'
|
||||
)
|
||||
})
|
||||
|
||||
it('should redirect the user to `/404` if member is not owner', () => {
|
||||
cy.task('startMockServer', [
|
||||
...authenticationHandlers,
|
||||
getGuildMemberNotOwnerWithGuildIdHandler,
|
||||
getChannelWithChannelIdHandler
|
||||
]).setCookie('refreshToken', 'refresh-token')
|
||||
cy.visit(`/application/${guildExample.id}/${channelExample.id}/settings`, {
|
||||
failOnStatusCode: false
|
||||
})
|
||||
.location('pathname')
|
||||
.should('eq', '/404')
|
||||
})
|
||||
|
||||
it('should redirect the user to `/404` if `guildId` or `channelId` are not numbers', () => {
|
||||
cy.task('startMockServer', authenticationHandlers).setCookie(
|
||||
'refreshToken',
|
||||
'refresh-token'
|
||||
)
|
||||
cy.visit('/application/abc/abc/settings', {
|
||||
failOnStatusCode: false
|
||||
})
|
||||
.location('pathname')
|
||||
.should('eq', '/404')
|
||||
})
|
||||
|
||||
it("should redirect the user to `/404` if `guildId` doesn't exist", () => {
|
||||
cy.task('startMockServer', [
|
||||
...authenticationHandlers,
|
||||
getChannelWithChannelIdHandler
|
||||
]).setCookie('refreshToken', 'refresh-token')
|
||||
cy.visit(`/application/123/${channelExample.id}/settings`, {
|
||||
failOnStatusCode: false
|
||||
})
|
||||
.location('pathname')
|
||||
.should('eq', '/404')
|
||||
})
|
||||
|
||||
it("should redirect the user to `/404` if `channelId` doesn't exist", () => {
|
||||
cy.task('startMockServer', [
|
||||
...authenticationHandlers,
|
||||
getGuildMemberWithGuildIdHandler
|
||||
]).setCookie('refreshToken', 'refresh-token')
|
||||
cy.visit(`/application/${guildExample.id}/123/settings`, {
|
||||
failOnStatusCode: false
|
||||
})
|
||||
.location('pathname')
|
||||
.should('eq', '/404')
|
||||
})
|
||||
})
|
@ -0,0 +1,74 @@
|
||||
import { postChannelsWithGuildIdHandler } from '../../../../../fixtures/guilds/[guildId]/channels/post'
|
||||
import { API_URL } from '../../../../../../tools/api'
|
||||
import { channelExample2 } from '../../../../../fixtures/channels/channel'
|
||||
import { guildExample } from '../../../../../fixtures/guilds/guild'
|
||||
import { getGuildMemberWithGuildIdHandler } from '../../../../../fixtures/guilds/[guildId]/get'
|
||||
import { authenticationHandlers } from '../../../../../fixtures/handler'
|
||||
import { getChannelWithChannelIdHandler2 } from '../../../../../fixtures/channels/[channelId]/get'
|
||||
|
||||
describe('Pages > /application/[guildId]/channels/create', () => {
|
||||
beforeEach(() => {
|
||||
cy.task('stopMockServer')
|
||||
})
|
||||
|
||||
it('should succeeds and create the channel', () => {
|
||||
cy.task('startMockServer', [
|
||||
...authenticationHandlers,
|
||||
getGuildMemberWithGuildIdHandler,
|
||||
postChannelsWithGuildIdHandler,
|
||||
getChannelWithChannelIdHandler2
|
||||
]).setCookie('refreshToken', 'refresh-token')
|
||||
cy.intercept(`${API_URL}${postChannelsWithGuildIdHandler.url}*`).as(
|
||||
'postChannelsWithGuildIdHandler'
|
||||
)
|
||||
cy.visit(`/application/${guildExample.id}/channels/create`)
|
||||
cy.get('[data-cy=channel-name-input]').type(channelExample2.name)
|
||||
cy.get('[data-cy=button-create-channel]').click()
|
||||
cy.wait('@postChannelsWithGuildIdHandler').then(() => {
|
||||
cy.location('pathname').should(
|
||||
'eq',
|
||||
`/application/${guildExample.id}/${channelExample2.id}`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it('should fails with too long channel name on update', () => {
|
||||
cy.task('startMockServer', [
|
||||
...authenticationHandlers,
|
||||
getGuildMemberWithGuildIdHandler
|
||||
]).setCookie('refreshToken', 'refresh-token')
|
||||
cy.visit(`/application/${guildExample.id}/channels/create`)
|
||||
cy.get('[data-cy=channel-name-input]').type(
|
||||
'random channel name that is really too long for a channel name'
|
||||
)
|
||||
cy.get('[data-cy=button-create-channel]').click()
|
||||
cy.get('#error-name').should(
|
||||
'have.text',
|
||||
'Error: The field must contain at most 20 characters.'
|
||||
)
|
||||
})
|
||||
|
||||
it('should redirect the user to `/404` if `guildId` is not a number', () => {
|
||||
cy.task('startMockServer', authenticationHandlers).setCookie(
|
||||
'refreshToken',
|
||||
'refresh-token'
|
||||
)
|
||||
cy.visit('/application/abc/channels/create', {
|
||||
failOnStatusCode: false
|
||||
})
|
||||
.location('pathname')
|
||||
.should('eq', '/404')
|
||||
})
|
||||
|
||||
it("should redirect the user to `/404` if `guildId` doesn't exist", () => {
|
||||
cy.task('startMockServer', [...authenticationHandlers]).setCookie(
|
||||
'refreshToken',
|
||||
'refresh-token'
|
||||
)
|
||||
cy.visit(`/application/123/channels/create`, {
|
||||
failOnStatusCode: false
|
||||
})
|
||||
.location('pathname')
|
||||
.should('eq', '/404')
|
||||
})
|
||||
})
|
104
cypress/integration/pages/application/[guildId]/settings.spec.ts
Normal file
104
cypress/integration/pages/application/[guildId]/settings.spec.ts
Normal file
@ -0,0 +1,104 @@
|
||||
import { deleteLeaveMembersWithGuildIdHandler } from 'cypress/fixtures/guilds/[guildId]/members/leave'
|
||||
|
||||
import { guildExample } from '../../../../fixtures/guilds/guild'
|
||||
import {
|
||||
getGuildMemberNotOwnerWithGuildIdHandler,
|
||||
getGuildMemberWithGuildIdHandler
|
||||
} from '../../../../fixtures/guilds/[guildId]/get'
|
||||
import { authenticationHandlers } from '../../../../fixtures/handler'
|
||||
import { API_URL } from '../../../../../tools/api'
|
||||
import { deleteGuildWithGuildIdHandler } from '../../../../fixtures/guilds/[guildId]/delete'
|
||||
|
||||
describe('Pages > /application/[guildId]/settings', () => {
|
||||
beforeEach(() => {
|
||||
cy.task('stopMockServer')
|
||||
})
|
||||
|
||||
it('should succeeds and display correctly the settings of the guild (member is owner)', () => {
|
||||
cy.task('startMockServer', [
|
||||
...authenticationHandlers,
|
||||
getGuildMemberWithGuildIdHandler
|
||||
]).setCookie('refreshToken', 'refresh-token')
|
||||
cy.visit(`/application/${guildExample.id}/settings`)
|
||||
cy.get('[data-cy=guild-name-input]').should('have.value', guildExample.name)
|
||||
cy.get('[data-cy=guild-description-input]').should(
|
||||
'have.value',
|
||||
guildExample.description
|
||||
)
|
||||
cy.get('[data-cy=button-save-guild-settings]').should('be.visible')
|
||||
cy.get('[data-cy=button-delete-guild-settings]').should('be.visible')
|
||||
cy.get('[data-cy=button-leave-guild-settings]').should('not.exist')
|
||||
})
|
||||
|
||||
it('should succeeds and display correctly the settings of the guild (member is not owner)', () => {
|
||||
cy.task('startMockServer', [
|
||||
...authenticationHandlers,
|
||||
getGuildMemberNotOwnerWithGuildIdHandler
|
||||
]).setCookie('refreshToken', 'refresh-token')
|
||||
cy.visit(`/application/${guildExample.id}/settings`)
|
||||
cy.get('[data-cy=guild-name-input]').should('not.exist')
|
||||
cy.get('[data-cy=guild-description-input]').should('not.exist')
|
||||
cy.get('[data-cy=button-save-guild-settings]').should('not.exist')
|
||||
cy.get('[data-cy=button-delete-guild-settings]').should('not.exist')
|
||||
cy.get('[data-cy=button-leave-guild-settings]').should('be.visible')
|
||||
})
|
||||
|
||||
it('should succeeds and leave the guild (member is not owner)', () => {
|
||||
cy.task('startMockServer', [
|
||||
...authenticationHandlers,
|
||||
getGuildMemberNotOwnerWithGuildIdHandler,
|
||||
deleteLeaveMembersWithGuildIdHandler
|
||||
]).setCookie('refreshToken', 'refresh-token')
|
||||
cy.intercept(`${API_URL}${deleteLeaveMembersWithGuildIdHandler.url}*`).as(
|
||||
'deleteLeaveMembersWithGuildIdHandler'
|
||||
)
|
||||
cy.visit(`/application/${guildExample.id}/settings`)
|
||||
cy.get('[data-cy=button-leave-guild-settings]').click()
|
||||
cy.wait('@deleteLeaveMembersWithGuildIdHandler').then(() => {
|
||||
cy.location('pathname').should('eq', '/application')
|
||||
})
|
||||
})
|
||||
|
||||
it('should succeeds and delete the guild', () => {
|
||||
cy.task('startMockServer', [
|
||||
...authenticationHandlers,
|
||||
getGuildMemberWithGuildIdHandler,
|
||||
deleteGuildWithGuildIdHandler
|
||||
]).setCookie('refreshToken', 'refresh-token')
|
||||
cy.intercept(`${API_URL}${deleteGuildWithGuildIdHandler.url}*`).as(
|
||||
'deleteGuildWithGuildIdHandler'
|
||||
)
|
||||
cy.visit(`/application/${guildExample.id}/settings`)
|
||||
cy.get('[data-cy=button-delete-guild-settings]').click()
|
||||
cy.wait('@deleteGuildWithGuildIdHandler').then((interception) => {
|
||||
expect(interception.response).to.not.be.eql(undefined)
|
||||
if (interception.response !== undefined) {
|
||||
expect(interception.response.statusCode).to.eq(200)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('should redirect the user to `/404` if `guildId` is not a number', () => {
|
||||
cy.task('startMockServer', authenticationHandlers).setCookie(
|
||||
'refreshToken',
|
||||
'refresh-token'
|
||||
)
|
||||
cy.visit('/application/abc/settings', {
|
||||
failOnStatusCode: false
|
||||
})
|
||||
.location('pathname')
|
||||
.should('eq', '/404')
|
||||
})
|
||||
|
||||
it("should redirect the user to `/404` if `guildId` doesn't exist", () => {
|
||||
cy.task('startMockServer', [...authenticationHandlers]).setCookie(
|
||||
'refreshToken',
|
||||
'refresh-token'
|
||||
)
|
||||
cy.visit(`/application/123/settings`, {
|
||||
failOnStatusCode: false
|
||||
})
|
||||
.location('pathname')
|
||||
.should('eq', '/404')
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user