Skip to content

Commit

Permalink
try unsucessfully to modify vite config to simplify relative paths fo…
Browse files Browse the repository at this point in the history
…r shared folder b00tc4mp#430
  • Loading branch information
juditta99 committed Apr 8, 2024
1 parent 57c8c22 commit bc730b6
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 25 deletions.
22 changes: 7 additions & 15 deletions staff/judy-grayland/project/api/logic/createActivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,19 @@ function createActivity(title, description, image, link) {
validate.text(image, 'image')
validate.text(link, 'link')

// return User.findById(userId)
// .lean()
// .catch((error) => {
// throw new SystemError(error.message)
// })
// .then((user) => {
// if (!user) {
// throw new NotFoundError('user not found')
// }

return Activity.create({
title,
description,
image,
link,
}).catch((error) => {
if (error.code === 11000) {
throw new DuplicityError('activity already exists')
}
throw new SystemError(error.message)
})
.catch((error) => {
if (error.code === 11000) {
throw new DuplicityError('activity already exists')
}
throw new SystemError(error.message)
})
.then((activity) => {})
}

export default createActivity
70 changes: 70 additions & 0 deletions staff/judy-grayland/project/api/logic/createActivity.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import dotenv from 'dotenv'
import mongoose from 'mongoose'
import { expect } from 'chai'
import random from './helpers/random.js'
import { errors } from 'shared'
const { DuplicityError, ContentError } = errors

import { Activity } from '../data/models.js'
import createActivity from './createActivity.js'

dotenv.config()

describe('createActivity', () => {
before(() => mongoose.connect(process.env.MONGODB_URL_TEST))
beforeEach(() => Activity.deleteMany())

// HAPPY path
it('succeeds on new activity begin correctly created', () => {
const title = random.title()
const description = random.description()
const image = random.image()
const link = random.link()

return createActivity(title, description, image, link).then((value) => {
expect(value).to.be.undefined
return Activity.findOne({ title: title }).then((activity) => {
expect(activity.description).to.equal(description)
expect(activity.image).to.equal(image)
expect(activity.link).to.equal(link)
})
})
})

it('fails on already existing activity', () => {
const title = random.title()
const description = random.description()
const image = random.image()
const link = random.link()

return Activity.create({ title, description, image, link }).then(
(activity) => {
return createActivity(title, description, image, link)
.then(() => {
throw new Error('should not reach this point')
})
.catch((error) => {
expect(error).to.be.instanceOf(DuplicityError)
expect(error.message).to.equal('activity already exists')
})
}
)
})

it('fails on empty field', () => {
const title = random.title()
const description = random.description()
const image = ''
const link = random.link()

// our validate.js catches the error and throws a ContentError because the image field is empty. We don't need to put a separate if logic that throws an error if one of the parameters(title, descrip, image or link) is missing. If we add that, it doesn't catch the error.
try {
return createActivity(title, description, image, link)
} catch (error) {
expect(error).to.be.instanceOf(ContentError)
expect(error.message).to.equal('image is empty')
}
})

after(() => mongoose.disconnect())
})
16 changes: 13 additions & 3 deletions staff/judy-grayland/project/api/logic/helpers/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,30 @@ function email() {
function password() {
return `password-${Math.random()}`
}
function title() {
return `title-${Math.random()}`
}

function description() {
return `description-${Math.random()}`
}
function image() {
return `image-${Math.random()}`
}

function text() {
return `text-${Math.random()}`
function link() {
return `link-www.${Math.random()}.com`
}

const random = {
name,
email,
password,

title,
description,
image,
text,
link,
}

export default random
3 changes: 2 additions & 1 deletion staff/judy-grayland/project/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.2"
"react-router-dom": "^6.22.2",
"shared": "file:../shared"
},
"devDependencies": {
"@types/react": "^18.2.56",
Expand Down
8 changes: 8 additions & 0 deletions staff/judy-grayland/project/app/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions staff/judy-grayland/project/app/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Routes, Route, NavLink, Navigate, Outlet } from 'react-router-dom'

import { Button } from './components'

import context from './logic/context'
import logic from './logic'

// pages
import Profile from './pages/Profile'
Expand All @@ -9,6 +12,7 @@ import Resources from './pages/Resources'
import Login from './pages/Login'
import Topic from './pages/Topic'
import Register from './pages/Register'
import { useNavigate } from 'react-router-dom'

function ProtectedRoute() {
// check if user is logged in
Expand All @@ -22,12 +26,19 @@ function ProtectedRoute() {
}

function App() {
const navigate = useNavigate()

function handleLogout() {
logic.logoutUser()
navigate('/')
}
return (
<>
<header>
<nav>
<NavLink to="profile">Profile</NavLink>
<NavLink to="/">Home</NavLink>
<Button onClick={handleLogout}>Log out</Button>
</nav>
</header>
<Routes>
Expand Down
14 changes: 14 additions & 0 deletions staff/judy-grayland/project/app/src/components/Field.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ function Field(props) {
</>
)
}
if (props.type === 'checkbox') {
return (
<>
<input
name={props.name}
type="checkbox"
id={props.inputId}
checked={props.checked}
onChange={props.onChange}
></input>
<label htmlFor={props.inputId}>{props.children}</label>
</>
)
}
return (
<>
<label htmlFor={props.inputId}>{props.children}</label>
Expand Down
2 changes: 2 additions & 0 deletions staff/judy-grayland/project/app/src/logic/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import registerUser from './registerUser'
import authenticateUser from './authenticateUser'
import logoutUser from './logoutUser'

const logic = {
registerUser,
authenticateUser,
logoutUser,
}

export default logic
8 changes: 8 additions & 0 deletions staff/judy-grayland/project/app/src/logic/logoutUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import context from './context'

function logoutUser() {
context.sessionUserId = null
context.token = null
}

export default logoutUser
53 changes: 47 additions & 6 deletions staff/judy-grayland/project/app/src/pages/Resources.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ function Resources() {
<h2>Recursos</h2>
<h3>Añade un recurso</h3>
<Form onSubmit={handleSubmit}>
{/* fieldset is an element used to group together part of a form. legend is used for the caption,ie.title */}
<fieldset>
<legend>Elige el tipo de recurso:</legend>
<Field
name="resourceType"
type="radio"
inputId="activity-radio"
// 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')}
>
Expand All @@ -44,9 +46,10 @@ function Resources() {
Fecha especial
</Field>
</fieldset>

{/* show different forms depending on what resource you choose */}
{resourceType === 'activity' && (
<fieldset>
<>
<Field name="title" inputId="title-input">
Título
</Field>
Expand All @@ -59,11 +62,49 @@ function Resources() {
<Field name="link" inputId="link-input">
Enlace
</Field>
<fieldset>
<legend>Selecciona los temas relacionados a la actividad</legend>
<Field
name="cultural-diversity"
type="checkbox"
inputId="cultural-diversity-check"
>
Diversidad cultural
</Field>
<Field name="topic-tag" type="checkbox" inputId="bullying-check">
Bullying
</Field>
<Field
name="functional-diversity"
type="checkbox"
inputId="functional-diversity-check"
>
Diversidad funcional
</Field>
<Field name="lgbt+" type="checkbox" inputId="lgbt+-check">
LGTB+
</Field>
<Field
name="gender-equality"
type="checkbox"
inputId="gender-equality-check"
>
Igualdad de género
</Field>
<Field
name="childrens-rights"
type="checkbox"
inputId="childrens-rights-check"
>
Derechos de la infancia
</Field>
</fieldset>

<Button>Añadir</Button>
</fieldset>
</>
)}
{resourceType === 'book' && (
<fieldset>
<>
<Field name="title" inputId="title-input">
Título
</Field>
Expand All @@ -80,10 +121,10 @@ function Resources() {
Enlace
</Field>
<Button type="submit">Añadir</Button>
</fieldset>
</>
)}
{resourceType === 'special-date' && (
<fieldset>
<>
<Field name="title" inputId="title-input">
Título
</Field>
Expand All @@ -100,7 +141,7 @@ function Resources() {
Enlace
</Field>
<Button type="submit">Añadir</Button>
</fieldset>
</>
)}
</Form>
</>
Expand Down

0 comments on commit bc730b6

Please sign in to comment.