feat: interact with user settings/profile (#9)
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
import { getUsersCurrentHandler } from './users/current/get'
|
||||
import { postUsersRefreshTokenHandler } from './users/refresh-token/post'
|
||||
|
||||
export type Method = 'GET' | 'POST' | 'PUT' | 'DELETE'
|
||||
|
||||
export interface Handler {
|
||||
method: 'GET' | 'POST' | 'PUT' | 'DELETE'
|
||||
method: Method
|
||||
url: `/${string}`
|
||||
response: {
|
||||
isFile?: boolean
|
||||
|
17
cypress/fixtures/users/[userId]/get.ts
Normal file
17
cypress/fixtures/users/[userId]/get.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { Handler } from '../../handler'
|
||||
import { userExample, userSettingsExample } from '../user'
|
||||
|
||||
export const getUserByIdHandler: Handler = {
|
||||
method: 'GET',
|
||||
url: `/users/${userExample.id}`,
|
||||
response: {
|
||||
statusCode: 200,
|
||||
body: {
|
||||
user: {
|
||||
...userExample,
|
||||
settings: userSettingsExample
|
||||
},
|
||||
guilds: []
|
||||
}
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ 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'
|
||||
import { getUserByIdHandler } from '../../../fixtures/users/[userId]/get'
|
||||
|
||||
const applicationPaths = [
|
||||
'/application',
|
||||
@ -32,7 +33,8 @@ describe('Common > application/authentication', () => {
|
||||
...authenticationHandlers,
|
||||
getGuildsHandler,
|
||||
getGuildMemberWithGuildIdHandler,
|
||||
getChannelWithChannelIdHandler
|
||||
getChannelWithChannelIdHandler,
|
||||
getUserByIdHandler
|
||||
]).setCookie('refreshToken', 'refresh-token')
|
||||
for (const applicationPath of applicationPaths) {
|
||||
cy.visit(applicationPath)
|
||||
|
@ -203,14 +203,16 @@ describe('Pages > /application/[guildId]/[channelId]', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('should redirect the user to `/application` if `guildId` or `channelId` are not numbers', () => {
|
||||
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')
|
||||
cy.visit('/application/abc/abc', {
|
||||
failOnStatusCode: false
|
||||
})
|
||||
.location('pathname')
|
||||
.should('eq', '/application')
|
||||
.should('eq', '/404')
|
||||
})
|
||||
|
||||
it("should redirect the user to `/404` if `guildId` doesn't exist", () => {
|
||||
|
@ -0,0 +1,35 @@
|
||||
import date from 'date-and-time'
|
||||
|
||||
import { userExample } from '../../../../../fixtures/users/user'
|
||||
import { getUserByIdHandler } from '../../../../../fixtures/users/[userId]/get'
|
||||
import { authenticationHandlers } from '../../../../../fixtures/handler'
|
||||
|
||||
describe('Pages > /application/users/[userId]', () => {
|
||||
beforeEach(() => {
|
||||
cy.task('stopMockServer')
|
||||
})
|
||||
|
||||
it('should succeeds and display the public user profile correctly', () => {
|
||||
cy.task('startMockServer', [
|
||||
...authenticationHandlers,
|
||||
getUserByIdHandler
|
||||
]).setCookie('refreshToken', 'refresh-token')
|
||||
cy.visit(`/application/users/${userExample.id}`)
|
||||
cy.get('[data-cy=user-name]').should('have.text', userExample.name)
|
||||
cy.get('[data-cy=user-email]').should('have.text', userExample.email)
|
||||
cy.get('[data-cy=user-createdAt]').should(
|
||||
'have.text',
|
||||
date.format(new Date(userExample.createdAt), 'DD/MM/YYYY')
|
||||
)
|
||||
})
|
||||
|
||||
it("should redirect the user to `/404` if `userId` doesn't exist", () => {
|
||||
cy.task('startMockServer', [...authenticationHandlers]).setCookie(
|
||||
'refreshToken',
|
||||
'refresh-token'
|
||||
)
|
||||
cy.visit(`/application/users/123`, { failOnStatusCode: false })
|
||||
.location('pathname')
|
||||
.should('eq', '/404')
|
||||
})
|
||||
})
|
@ -6,6 +6,10 @@ import { API_DEFAULT_PORT } from '../../tools/api'
|
||||
|
||||
/// <reference types="cypress" />
|
||||
|
||||
/**
|
||||
* @typedef {import('../fixtures/handler').Method} Method
|
||||
*/
|
||||
|
||||
/** @type {import('mockttp').Mockttp | null} */
|
||||
let server = null
|
||||
|
||||
@ -31,13 +35,16 @@ module.exports = (on, config) => {
|
||||
await server.start(API_DEFAULT_PORT)
|
||||
for (const handler of handlers) {
|
||||
const { isFile = false } = handler.response
|
||||
const method = /** @type {Lowercase<Method>} */ (
|
||||
handler.method.toLowerCase()
|
||||
)
|
||||
if (isFile) {
|
||||
await server[handler.method.toLowerCase()](handler.url).thenFromFile(
|
||||
await server[method](handler.url).thenFromFile(
|
||||
handler.response.statusCode,
|
||||
path.join(UPLOADS_FIXTURES_DIRECTORY, ...handler.response.body)
|
||||
)
|
||||
} else {
|
||||
await server[handler.method.toLowerCase()](handler.url).thenJson(
|
||||
await server[method](handler.url).thenJson(
|
||||
handler.response.statusCode,
|
||||
handler.response.body
|
||||
)
|
||||
|
Reference in New Issue
Block a user