Skip to content

Commit

Permalink
feat #1369: change validateCreate to validatePut, CREATE_REQUIRED_PAR…
Browse files Browse the repository at this point in the history
…AMS to PUT_REQUIRED_PARAMS
  • Loading branch information
undefined committed May 28, 2020
1 parent 317d47d commit b573b99
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { validateGetById, validateCreate, validateUpdate, validateDelete, validateFollowSchema } from '../validators'
import { validateGetById, validatePut, validateUpdate, validateDelete, validateFollowSchema } from '../validators'

describe('validateGetById', () => {
it('should return correctly', () => {
Expand Down Expand Up @@ -34,9 +34,9 @@ describe('validateGetById', () => {
})
})

describe('validateCreate', () => {
describe('validatePut', () => {
it('should return correctly', () => {
const result = validateCreate({
const result = validatePut({
customerId: 'id1',
appointmentLength: 10,
appointmentTimeGap: 15,
Expand All @@ -52,7 +52,7 @@ describe('validateCreate', () => {
error.message = 'Invalid params'
error.code = '400'
expect(() => {
validateCreate({
validatePut({
customerId: 'id1',
appointmentLength: 10,
appointmentTimeGap: 15,
Expand All @@ -68,7 +68,7 @@ describe('validateCreate', () => {
error.message = 'Invalid params'
error.code = '400'
expect(() => {
validateCreate({
validatePut({
customerId: 'id1',
appointmentTimeGap: 15,
appointmentTypes: ['type1', 'type2'],
Expand All @@ -81,7 +81,7 @@ describe('validateCreate', () => {
error.message = 'Invalid daysOfWeek.'
error.code = '400'
expect(() => {
validateCreate({
validatePut({
customerId: 'id1',
appointmentLength: 10,
appointmentTimeGap: 15,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const ALL_PARAMS = [
'daysOfWeek',
]
export const GET_BY_ID_REQUIRED_PARAMS = ['customerId']
export const CREATE_REQUIRED_PARAMS = [
export const PUT_REQUIRED_PARAMS = [
'customerId',
'appointmentLength',
'appointmentTimeGap',
Expand Down Expand Up @@ -68,12 +68,12 @@ export const validateGetById = (data: { [key: string]: any }) => {
return true
}

export const validateCreate = (data: { [key: string]: any }) => {
export const validatePut = (data: { [key: string]: any }) => {
const dataKeys = Object.keys(data)

// check if param keys are valid
const isParamsValid =
dataKeys.every(key => CREATE_REQUIRED_PARAMS.includes(key)) && dataKeys.length === CREATE_REQUIRED_PARAMS.length
dataKeys.every(key => PUT_REQUIRED_PARAMS.includes(key)) && dataKeys.length === PUT_REQUIRED_PARAMS.length
// check if param is a valid schema item
const errorMessage = validateFollowSchema(data)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import express from 'express'
import { getConfigByClientId, createConfig, deleteConfig, updateConfig } from './api'
import { AppRequest, AppResponse } from '@/app'
import logger from '@/logger'
import { validateGetById, validateCreate, validateUpdate, validateDelete } from './validators'
import { validateGetById, validatePut, validateUpdate, validateDelete } from './validators'

const webComponentsConfig = express.Router()

Expand All @@ -26,7 +26,7 @@ export const webComponentsConfigPutHandler = async (req: AppRequest, res: AppRes
try {
const params = { traceId: req.traceId, data: req.body }
const { data } = params
validateCreate(data)
validatePut(data)
const result = await createConfig(params)
return res.send(result)
} catch (err) {
Expand Down

0 comments on commit b573b99

Please sign in to comment.