forked from b00tc4mp/isdi-parttime-202309
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add spec tests to all logics b00tc4mp#406; start tailwind css b00tc4m…
- Loading branch information
Showing
66 changed files
with
3,069 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
staff/miguel-arias/project/api/handlers/retrieveProfileTasksHandler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import jwt from 'jsonwebtoken' | ||
const { JsonWebTokenError } = jwt | ||
|
||
import { errors } from 'com' | ||
const { NotFoundError, ContentError, TokenError } = errors | ||
|
||
import logic from "../logic/index.js" | ||
|
||
export default async (req, res) => { | ||
try { | ||
const token = req.headers.authorization.substring(7) | ||
const payload = jwt.verify(token, process.env.JWT_SECRET) | ||
const homeId = payload.sub | ||
|
||
const { profileId, week } = req.params | ||
|
||
const tasks = await logic.retrieveProfileTasks(homeId, profileId, week) | ||
|
||
res.json(tasks) | ||
|
||
} catch (error) { | ||
let status = 500 | ||
|
||
if (error instanceof ContentError || error instanceof TypeError) | ||
status = 406 | ||
|
||
if (error instanceof NotFoundError) | ||
status = 404 | ||
|
||
if (error instanceof JsonWebTokenError) { | ||
status = 401 | ||
error = new TokenError(error.message) | ||
} | ||
|
||
res.status(status).json({ error: error.constructor.name, message: error.message }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
staff/miguel-arias/project/api/logic/assignTask.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import dotenv from 'dotenv' | ||
dotenv.config() | ||
|
||
import mongoose from 'mongoose' | ||
import { expect } from 'chai' | ||
|
||
import random from './helpers/random.js' | ||
import assignTask from './assignTask.js' | ||
import { Profile, Template, Task } from '../data/models.js' | ||
|
||
import { errors } from 'com' | ||
const { NotFoundError, PermissionError } = errors | ||
debugger | ||
describe('assignTask', () => { | ||
before(() => mongoose.connect('mongodb://127.0.0.1:27017/spec')) | ||
|
||
beforeEach(() => Promise.all([Profile.deleteMany(), Template.deleteMany(), Task.deleteMany()])) | ||
|
||
it('succeeds on existing session profile, profile and task', async () => { | ||
|
||
const sessionProfile = await Profile.create({ home: random.id(), name: random.name(), pincode: random.pincode(), role: 'admin' }) | ||
|
||
const sessionProfileId = sessionProfile._id.toString() | ||
|
||
const profile = await Profile.create({ home: random.id(), name: random.name(), pincode: random.pincode(), color: { name: random.name(), code: random.name() } }) | ||
|
||
const profileId = profile._id.toString() | ||
|
||
const task = await Task.create({ home: random.id(), template: random.id(), assignee: random.id() }) | ||
|
||
const taskId = task._id.toString() | ||
|
||
await assignTask(sessionProfileId, taskId, profileId) | ||
|
||
const taskFound = await Task.findById(taskId) | ||
debugger | ||
expect(taskFound.assignee._id.toString()).to.equal(profileId) | ||
}) | ||
|
||
it('succeeds on only existing session profile and task', async () => { | ||
|
||
const sessionProfile = await Profile.create({ home: random.id(), name: random.name(), pincode: random.pincode(), role: 'admin' }) | ||
|
||
const sessionProfileId = sessionProfile._id.toString() | ||
|
||
const profile = await Profile.create({ home: random.id(), name: random.name(), pincode: random.pincode(), role: 'admin', color: { name: random.name(), code: random.name() } }) | ||
|
||
const profileId = profile._id.toString() | ||
|
||
const task = await Task.create({ home: random.id(), template: random.id(), assignee: random.id() }) | ||
|
||
const taskId = task._id.toString() | ||
|
||
await assignTask(sessionProfileId, taskId, null) | ||
|
||
const taskFound = await Task.findById(taskId) | ||
|
||
expect(taskFound.assignee._id.toString()).to.equal(sessionProfileId) | ||
}) | ||
|
||
it('fails on non existing task', async () => { | ||
try { | ||
await assignTask(random.id(), random.id(), random.id()) | ||
throw new Error('should not reach this point') | ||
} catch (error) { | ||
expect(error).to.be.instanceOf(NotFoundError) | ||
expect(error.message).to.equal('task not found') | ||
} | ||
}) | ||
|
||
it('fails on non existing session profile', async () => { | ||
const task = await Task.create({ home: random.id(), template: random.id(), assignee: random.id() }) | ||
|
||
const taskId = task._id.toString() | ||
try { | ||
await assignTask(random.id(), taskId, null) | ||
throw new Error('should not reach this point') | ||
} catch (error) { | ||
expect(error).to.be.instanceOf(NotFoundError) | ||
expect(error.message).to.equal('session profile not found') | ||
} | ||
}) | ||
|
||
it('fails on profile not admin', async () => { | ||
const sessionProfile = await Profile.create({ home: random.id(), name: random.name(), pincode: random.id() }) | ||
|
||
const sessionProfileId = sessionProfile._id.toString() | ||
|
||
const task = await Task.create({ home: random.id(), template: random.id(), assignee: random.id() }) | ||
|
||
const taskId = task._id.toString() | ||
try { | ||
await assignTask(sessionProfileId, taskId, null) | ||
throw new Error('should not reach this point') | ||
} catch (error) { | ||
expect(error).to.be.instanceOf(PermissionError) | ||
expect(error.message).to.equal('profile is not admin') | ||
} | ||
}) | ||
|
||
it('fails on non existing profile', async () => { | ||
const task = await Task.create({ home: random.id(), template: random.id(), assignee: random.id() }) | ||
|
||
const taskId = task._id.toString() | ||
try { | ||
await assignTask(random.id(), taskId, random.id()) | ||
throw new Error('should not reach this point') | ||
} catch (error) { | ||
expect(error).to.be.instanceOf(NotFoundError) | ||
expect(error.message).to.equal('profile not found') | ||
} | ||
}) | ||
|
||
after(async () => await mongoose.disconnect()) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.