Commit 9f8fc61c authored by rlacko's avatar rlacko 💬
Browse files

Mentor documentation

parent afef4019
Pipeline #4725 passed with stages
in 2 minutes
......@@ -91,7 +91,7 @@ components:
properties:
activity:
type: string
description: cuid of each attendance
description: cuid of the activity
user:
type: string
description: schacc of the user
......
......@@ -4,27 +4,26 @@ const { merge, has } = require('lodash')
const { validateKeys } = require('../../../utils/testHelpers')
const { User } = require('../../user/userModel')
const {Mentor}= require('../mentorModel')
const { Mentor } = require('../mentorModel')
const endpointUrl = '/api/v1/mentor'
const fakeUserJson = {
internal_id: 'fakeId',
schacc: 'fakeUser',
fullName: 'faker Janos',
secondaryEmail: 'faker@fake.com',
}
let fakeMentorsJson={
user:fakeUserJson.schacc,
description:'Legjobb mentor ever',
}
const defaultKeys={
_id:true,
user:true,
description:true,
}
internal_id: 'fakeId',
schacc: 'fakeUser',
fullName: 'faker Janos',
secondaryEmail: 'faker@fake.com',
}
let fakeMentorsJson = {
user: fakeUserJson.schacc,
description: 'Legjobb mentor ever',
}
const defaultKeys = {
_id: true,
user: true,
description: true,
}
describe('/mentor "Mentor" Functionality', () => {
describe('/mentor "Mentor" Functionality', () => {
let authSession
// Login as mentor
beforeEach(async function (done) {
......@@ -35,58 +34,60 @@ let fakeMentorsJson={
return done()
})
})
//readone
test(`GET existing mentor`, async () => {
const newMentor = await Mentor.create(fakeMentorsJson)
let response = await authSession.get(`${endpointUrl}/${newMentor._id}`)
expect(response.statusCode).toBe(200)
})
test('GET invalid mentor',async()=>{
let response=await authSession.get(`${endpointUrl}/almafa`)
expect(response.statusCode).toBe(422)
})
// Get Many
test(`GET many returns with allowed keys`, async () => {
await Mentor.create(fakeMentorsJson)
await Mentor.create(fakeMentorsJson)
let response = await authSession.get(endpointUrl)
expect(response.statusCode).toBe(200)
response.body.data.forEach((eachData) => {
validateKeys(eachData, defaultKeys)
})
})
// Create
test(`Create mentor`, async () => {
const newUser = await User.create(fakeUserJson)
const newMentor = await Mentor.create(fakeMentorsJson)
let response =await authSession.post(`${endpointUrl}/`).send({
user:newUser.schacc,
description:'Legjobb mentor ever',
})
expect(response.statusCode).toBe(201)
validateKeys(response.body.data, defaultKeys)
})
//Update
test(`Update mentor`,async()=>{
const newMentor=await Mentor.create(fakeMentorsJson)
let response=await authSession
.put(`${endpointUrl}/${newMentor._id}`)
.send({
description:'updateddescription',
})
expect(response.statusCode).toBe(200)
expect(response.body.data.description).toBe('updateddescription')
})
//Delete
test(`Delete mentor`,async ()=>{
const newMentor = await Mentor.create(fakeMentorsJson)
let response=await authSession.delete(`${endpointUrl}/${newMentor._id}`)
expect(response.statusCode).toBe(200)
})
})
//Nem számít az ,hogy melyikkel teszteled mert mind2nak ugyan olyannak kell lennie.
//readone
test(`GET existing mentor`, async () => {
const newMentor = await Mentor.create(fakeMentorsJson)
let response = await authSession.get(`${endpointUrl}/id/${newMentor._id}`)
expect(response.statusCode).toBe(200)
})
test('GET invalid mentor', async () => {
let response = await authSession.get(`${endpointUrl}/id/almafa`)
expect(response.statusCode).toBe(422)
})
// Get Many
test(`GET many returns with allowed keys`, async () => {
await Mentor.create(fakeMentorsJson)
await Mentor.create(fakeMentorsJson)
let response = await authSession.get(endpointUrl)
expect(response.statusCode).toBe(200)
response.body.data.forEach((eachData) => {
validateKeys(eachData, defaultKeys)
})
})
// Create
test(`Create mentor`, async () => {
const newUser = await User.create(fakeUserJson)
const newMentor = await Mentor.create(fakeMentorsJson)
let response = await authSession.post(`${endpointUrl}/`).send({
user: newUser.schacc,
description: 'Legjobb mentor ever',
})
expect(response.statusCode).toBe(201)
validateKeys(response.body.data, defaultKeys)
})
//Update
test(`Update mentor`, async () => {
const newMentor = await Mentor.create(fakeMentorsJson)
let response = await authSession
.put(`${endpointUrl}/id/${newMentor._id}`)
.send({
description: 'updateddescription',
})
expect(response.statusCode).toBe(200)
expect(response.body.data.description).toBe('updateddescription')
})
//Delete
test(`Delete mentor`, async () => {
const newMentor = await Mentor.create(fakeMentorsJson)
let response = await authSession.delete(
`${endpointUrl}/id/${newMentor._id}`
)
expect(response.statusCode).toBe(200)
})
})
//Nem számít az ,hogy melyikkel teszteled mert mind2nak ugyan olyannak kell lennie.
//normal=accepted
describe('/mentor "Accepted" Functionality', () => {
describe('/mentor "Accepted" Functionality', () => {
let authSession
// Login as accepted and create a group
beforeEach(async function (done) {
......@@ -97,26 +98,25 @@ let fakeMentorsJson={
return done()
})
})
//readone
test(`GET existing mentor`, async () => {
const newUser= await User.create(fakeUserJson)
const newMentor = await Mentor.create(fakeMentorsJson)
let response = await authSession.get(`${endpointUrl}/${newMentor._id}`)
expect(response.statusCode).toBe(200)
})
test('GET invalid mentor',async()=>{
let response=await authSession.get(`${endpointUrl}/almafa`)
expect(response.statusCode).toBe(422)
})
// Get Many
test(`GET many returns with allowed keys`, async () => {
await Mentor.create(fakeMentorsJson)
await Mentor.create(fakeMentorsJson)
let response = await authSession.get(endpointUrl)
expect(response.statusCode).toBe(200)
response.body.data.forEach((eachData) => {
validateKeys(eachData, defaultKeys)
})
})
//readone
test(`GET existing mentor`, async () => {
const newUser = await User.create(fakeUserJson)
const newMentor = await Mentor.create(fakeMentorsJson)
let response = await authSession.get(`${endpointUrl}/id/${newMentor._id}`)
expect(response.statusCode).toBe(200)
})
test('GET invalid mentor', async () => {
let response = await authSession.get(`${endpointUrl}/id/almafa`)
expect(response.statusCode).toBe(422)
})
// Get Many
test(`GET many returns with allowed keys`, async () => {
await Mentor.create(fakeMentorsJson)
await Mentor.create(fakeMentorsJson)
let response = await authSession.get(endpointUrl)
expect(response.statusCode).toBe(200)
response.body.data.forEach((eachData) => {
validateKeys(eachData, defaultKeys)
})
})
})
......@@ -11,13 +11,28 @@ const fakeMentorJson = {
}
describe('/mentor Permission tests', () => {
crudPermTest(
app,
endpointUrl + '/id',
Mentor,
'mentor',
fakeMentorJson,
[false, false, true, true, true],
[
// [role, create, readAll, readOne, update, delete]
['none', false, false, false, false, false],
['normal', false, true, true, false, false],
['accepted', false, true, true, false, false],
['mentor', true, true, true, true, true],
]
)
crudPermTest(
app,
endpointUrl,
Mentor,
'mentor',
fakeMentorJson,
[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: 'Mentor Endpoint'
version: '1.0'
paths:
/mentor:
get:
tags:
- 'Mentor'
summary: 'Get a List of mentors'
description: 'Have to be logged in.'
operationId: 'getAllMentor'
responses:
'200':
description: OK
content:
application/json:
schema:
type: 'array'
items:
$ref: '#/components/schemas/Mentor'
post:
tags:
- 'Mentor'
summary: 'Create a mentor'
description: 'Have to be mentor for this.'
operationId: 'createMentor'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Mentor'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Mentor'
/mentor/id/{id}:
get:
tags:
- 'Mentor'
summary: 'Get a mentor by ID'
description: 'Have to be logged in for this.'
operationId: 'getMentor'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Mentor'
put:
tags:
- 'Mentor'
summary: 'Update a mentor by ID'
description: 'Only mentors can update a mentor.'
operationId: 'updateOneMentor'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Mentor'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Mentor'
delete:
tags:
- 'Mentor'
summary: 'Delete a mentor by ID'
description: 'Only mentors can delete a mentor.'
operationId: 'deleteMentor'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Mentor'
components:
schemas:
Mentor:
type: object
properties:
user:
type: string
description: schacc of the user
description:
type: string
required:
- user
- description
......@@ -5,15 +5,15 @@ const { isLoggedIn, isMentor } = require('../../middlewares/auth')
const router = Router()
// /api/item
// /api/v1/mentor
router
.route('/')
.get(isLoggedIn, controllers.default.getMany)
.post(isLoggedIn, isMentor, controllers.default.createOne)
// /api/item/:id
// /api/v1/mentor/id/:id
router
.route('/:id')
.route('/id/:id')
.get(isLoggedIn, 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