2022-03-05 18:22:30 +01:00
|
|
|
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()
|
2022-04-09 13:48:48 +02:00
|
|
|
cy.get('[data-cy=confirm-popup-yes-button]').click()
|
2022-03-05 18:22:30 +01:00
|
|
|
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
|
|
|
|
})
|
2022-08-30 21:30:06 +02:00
|
|
|
.get('[data-cy=status-code]')
|
|
|
|
.contains('404')
|
2022-03-05 18:22:30 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
|
})
|
2022-08-30 21:30:06 +02:00
|
|
|
.get('[data-cy=status-code]')
|
|
|
|
.contains('404')
|
2022-03-05 18:22:30 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
|
})
|
2022-08-30 21:30:06 +02:00
|
|
|
.get('[data-cy=status-code]')
|
|
|
|
.contains('404')
|
2022-03-05 18:22:30 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
|
})
|
2022-08-30 21:30:06 +02:00
|
|
|
.get('[data-cy=status-code]')
|
|
|
|
.contains('404')
|
2022-03-05 18:22:30 +01:00
|
|
|
})
|
|
|
|
})
|
2022-08-23 21:51:20 +02:00
|
|
|
|
|
|
|
export {}
|