Skip to content

Commit

Permalink
remove onChange hook from radio buttons so resource type cannot be ed…
Browse files Browse the repository at this point in the history
…ited; add some tests to edit resource spec in backend b00tc4mp#484
  • Loading branch information
juditta99 committed Jun 19, 2024
1 parent c89a2a6 commit f40080b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 61 deletions.
111 changes: 54 additions & 57 deletions staff/judy-grayland/project/api/logic/editResource.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('edit resource', () => {
}

const newData = {
title: 'Bee Bop Bops',
title: 'Oh La La 6',
author: 'Billy Bee Boo',
}
return Resource.create(initialData).then((resource) => {
Expand All @@ -45,65 +45,62 @@ describe('edit resource', () => {
})
})

// // HAPPY path - activity
// it('succeeds on new activity being correctly created', () => {
// const title = random.title()
// const description = random.description()
// const resourceType = 'activity'
// const topic = ['igualdad de genero']
// const link = random.link()
// const image = random.image()
// const author = ''
// const ageRange = ''
// HAPPY path - activity
it('succeeds on activity being correctly edited', () => {
const initialData = {
title: random.title(),
description: random.description(),
resourceType: 'activity',
topic: ['igualdad de genero'],
link: random.link(),
image: random.image(),
}

// return createResource({
// title,
// description,
// resourceType,
// topic,
// link,
// image,
// author,
// ageRange,
// }).then((value) => {
// expect(value).to.be.undefined
// return Resource.findOne({ title: title }).then((resource) => {
// expect(resource.description).to.equal(description)
// expect(resource.link).to.equal(link)
// expect(resource.resourceType).to.equal(resourceType)
// expect(resource.topic).to.deep.equal(topic)
// expect(resource.image).to.equal(image)
// expect(resource.author).to.equal('')
// expect(resource.ageRange).to.deep.equal([''])
// })
// })
// })
// })
const newData = {
topic: ['bullying'],
}

// // UNHAPPY path - activity on missing required field for all resources
// it('fails on missing resourceType', async () => {
// const title = random.title()
// const description = random.description()
// const resourceType = ''
// const topic = ['bullying']
// const link = random.link()
// const image = random.image()
// const author = ''
// const ageRange = ''
return Resource.create(initialData).then((resource) => {
return editResource(resource._id, newData)
.then(() => Resource.findOne(resource._id))
.then((updatedResource) => {
expect(updatedResource.title).to.equal(initialData.title)
expect(updatedResource.link).to.equal(initialData.link)
expect(updatedResource.resourceType).to.equal(
initialData.resourceType
)
expect(updatedResource.topic).to.deep.equal(newData.topic)
expect(updatedResource.image).to.equal(initialData.image)
})
})
})

// await expect(() => {
// createResource({
// title,
// description,
// resourceType,
// topic,
// link,
// image,
// author,
// ageRange,
// }).to.throw(ContentError, 'resourceType is empty')
// })
// })
// UNHAPPY path - activity on missing required field for all resources
it('fails on activity being edited with empty field', () => {
const initialData = {
title: random.title(),
description: random.description(),
resourceType: 'activity',
topic: ['igualdad de genero'],
link: random.link(),
image: random.image(),
}

const newData = {
title: '',
}

return Resource.create(initialData).then((resource) => {
return editResource(resource._id, newData)
.then(() => {
throw new Error('should not reach this point')
})
.catch((error) => {
expect(error).to.be.instanceOf(ContentError)
expect(error.message).to.equal('title is empty')
})
})
})

// // UNHAPPY path - book on already existing resources
// it('fails on already existing resource', () => {
Expand Down
11 changes: 7 additions & 4 deletions staff/judy-grayland/project/app/src/pages/EditResource.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ function EditResource() {
value="activity"
// resourceType is a variable. Checked is an attribute on an HTML tag that accepts true or false. If it coincides with the string "activity", it evaluates to true and that makes it checked.
checked={resourceType === 'activity'}
onChange={() => setResourceType('activity')}
// onChange={() => setResourceType('activity')}
// disabled={true}
>
Actividad
</Field>
Expand All @@ -106,7 +107,8 @@ function EditResource() {
inputId="book-radio"
value="book"
checked={resourceType === 'book'}
onChange={() => setResourceType('book')}
// onChange={() => setResourceType('book')}
// disabled={true}
>
Libro
</Field>
Expand All @@ -116,7 +118,8 @@ function EditResource() {
inputId="date-radio"
value="date"
checked={resourceType === 'date'}
onChange={() => setResourceType('date')}
// onChange={() => setResourceType('date')}
// disabled={true}
>
Fecha especial
</Field>
Expand All @@ -131,7 +134,7 @@ function EditResource() {
<Field
name="description"
inputId="description-input"
defaultValue={resource.description}
value={resource.description}
>
Descripción
</Field>
Expand Down

0 comments on commit f40080b

Please sign in to comment.