Made POST requests actual post requests

This commit is contained in:
RemixDev
2022-01-13 01:27:08 +01:00
parent 62cb39f154
commit bb6e4bec0d
8 changed files with 22 additions and 22 deletions

View File

@@ -1,15 +0,0 @@
import { appSendGet } from '../../../../tests/utils'
describe('analyzeLink requests', () => {
it('should respond 200 to calls with supported child number', async () => {
const res = await appSendGet('/api/changeAccount/?child=1')
expect(res.status).toBe(200)
})
it('should respond 400 to calls with not supported child number', async () => {
const res = await appSendGet('/api/changeAccount/')
expect(res.status).toBe(400)
})
})

View File

@@ -1,31 +0,0 @@
import { RequestHandler } from 'express'
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types'
import { sessionDZ } from '../../../main'
const path: ApiHandler['path'] = '/changeAccount'
interface ChangeAccountQuery {
child: number
}
const handler: RequestHandler<{}, {}, {}, ChangeAccountQuery> = (req, res) => {
if (!req.query || !req.query.child) {
return res.status(400).send({ errorMessage: 'No child specified', errorCode: 'CA01' })
}
const { child: accountNum } = req.query
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
const dz = sessionDZ[req.session.id]
const accountData = dz.change_account(accountNum)
return res.status(200).send(accountData)
}
const apiHandler: ApiHandler = { path, handler }
export default apiHandler

View File

@@ -1,5 +1,4 @@
import analyzeLink from './analyzeLink'
import changeAccount from './changeAccount'
import getHome from './getHome'
import getCharts from './getCharts'
import mainSearch from './mainSearch'
@@ -20,7 +19,6 @@ import spotifyStatus from './spotifyStatus'
export default [
albumSearch,
changeAccount,
analyzeLink,
getHome,
getCharts,