Commit 0f8f83d3 authored by rlacko's avatar rlacko 💬
Browse files

Task documentation

parent ea728345
Pipeline #4728 passed with stages
in 1 minute and 52 seconds
......@@ -41,11 +41,11 @@ describe('/task "Mentor" Functionality', () => {
//readone
test(`GET existing task`, async () => {
const newTask = await Task.create(fakeTaskJson)
let response = await authSession.get(`${endpointUrl}/${newTask._id}`)
let response = await authSession.get(`${endpointUrl}/id/${newTask._id}`)
expect(response.statusCode).toBe(200)
})
test('GET invalid task', async () => {
let response = await authSession.get(`${endpointUrl}/almafa`)
let response = await authSession.get(`${endpointUrl}/id/almafa`)
expect(response.statusCode).toBe(422)
})
// Get Many
......@@ -74,16 +74,18 @@ describe('/task "Mentor" Functionality', () => {
//Update
test(`Update task`, async () => {
const newTask = await Task.create(fakeTaskJson)
let response = await authSession.put(`${endpointUrl}/${newTask._id}`).send({
title: 'updatedtitle',
})
let response = await authSession
.put(`${endpointUrl}/id/${newTask._id}`)
.send({
title: 'updatedtitle',
})
expect(response.statusCode).toBe(200)
expect(response.body.data.title).toBe('updatedtitle')
})
//Delete
test(`Delete task`, async () => {
const newTask = await Task.create(fakeTaskJson)
let response = await authSession.delete(`${endpointUrl}/${newTask._id}`)
let response = await authSession.delete(`${endpointUrl}/id/${newTask._id}`)
expect(response.statusCode).toBe(200)
})
})
......@@ -103,11 +105,11 @@ describe('/task "Accepted" Functionality', () => {
//readone
test(`GET existing task`, async () => {
const newTask = await Task.create(fakeTaskJson)
let response = await authSession.get(`${endpointUrl}/${newTask._id}`)
let response = await authSession.get(`${endpointUrl}/id/${newTask._id}`)
expect(response.statusCode).toBe(200)
})
test('GET invalid task', async () => {
let response = await authSession.get(`${endpointUrl}/almafa`)
let response = await authSession.get(`${endpointUrl}/id/almafa`)
expect(response.statusCode).toBe(422)
})
// Get Many
......
......@@ -15,13 +15,28 @@ const fakeTaskJson = {
}
describe('/task Permission tests', () => {
crudPermTest(
app,
endpointUrl + '/id',
Task,
'task',
fakeTaskJson,
[false, false, true, true, true],
[
// [role, create, readAll, readOne, update, delete]
['none', false, false, false, false, false],
['normal', false, false, false, false, false],
['accepted', false, true, true, false, false],
['mentor', true, true, true, true, true],
]
)
crudPermTest(
app,
endpointUrl,
Task,
'task',
fakeTaskJson,
[true, true, true, true, true],
[true, true, false, false, false],
[
// [role, create, readAll, readOne, update, delete]
['none', false, false, false, false, false],
......
openapi: '3.0.2'
info:
title: 'Task Endpoint'
version: '1.0'
paths:
/task:
get:
tags:
- 'Task'
summary: 'Get a List of tasks'
description: 'Have to be accepted or mentor.'
operationId: 'getAllTask'
responses:
'200':
description: OK
content:
application/json:
schema:
type: 'array'
items:
$ref: '#/components/schemas/Task'
post:
tags:
- 'Task'
summary: 'Create a task'
description: 'Have to be mentor.'
operationId: 'createTask'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Task'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Task'
/task/id/{id}:
get:
tags:
- 'Task'
summary: 'Get a task by ID'
description: 'Have to be accepted or mentor.'
operationId: 'getTask'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Task'
put:
tags:
- 'Task'
summary: 'Update a task by ID'
description: 'Have to be mentor.'
operationId: 'updateOneTask'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Task'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Task'
delete:
tags:
- 'Task'
summary: 'Delete a task by ID'
description: 'Have to be mentor.'
operationId: 'deleteTask'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Task'
components:
schemas:
Task:
type: object
properties:
title:
type: string
description:
type: string
deadline:
type: string
format: date-time
bit:
type: number
default: 0
creator:
type: string
description: schacc of the user. Default is the current user.
tasks:
type: array
items:
type: string
description: cuid of each task
comments:
type: array
items:
type: string
description: cuid of each comment
required:
- title
- description
- deadline
- bit
......@@ -16,7 +16,8 @@ const TaskSchema = new mongoose.Schema(
},
bit: {
type: Number,
require: true,
required: true,
default: 0,
},
creator: {
type: String,
......@@ -25,14 +26,12 @@ const TaskSchema = new mongoose.Schema(
{
type: mongoose.Schema.Types.ObjectId,
ref: 'solution',
required: true,
},
],
comments: [
{
type: mongoose.Schema.Types.ObjectId,
ref: 'comment',
required: true,
},
],
},
......
......@@ -9,15 +9,15 @@ const {
const router = Router()
// /api/item
// /api/v1/task
router
.route('/')
.get(isLoggedIn, isAcceptedOrMentor, controllers.default.getMany)
.post(isLoggedIn, isMentor, controllers.default.createOne)
// /api/item/:id
// /api/v1/task/id/:id
router
.route('/:id')
.route('/id/:id')
.get(isLoggedIn, isAcceptedOrMentor, controllers.default.getOne)
.put(isLoggedIn, isMentor, controllers.default.updateOne)
.delete(isLoggedIn, isMentor, controllers.default.removeOne)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment