Commit e34c9cfa authored by rlacko's avatar rlacko 💬
Browse files

Merge branch 'feature/kszkep-19-tests-arcter' into 'dev'

tests from arcter

See merge request !15
parents 2f7d48e6 55449775
Pipeline #4715 passed with stages
in 1 minute and 41 seconds
const { app } = require('../../../server')
const session = require('supertest-session')
const { merge, has } = require('lodash')
const { validateKeys } = require('../../../utils/testHelpers')
const { User } = require('../../user/userModel')
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,
}
describe('/mentor "Mentor" Functionality', () => {
let authSession
// Login as mentor
beforeEach(async function (done) {
let testSession = session(app)
testSession.get(`/api/v1/login/mock/mentor`).end(function (err) {
if (err) return done(err)
authSession = testSession
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.
//normal=accepted
describe('/mentor "Accepted" Functionality', () => {
let authSession
// Login as accepted and create a group
beforeEach(async function (done) {
let testSession = session(app)
testSession.get(`/api/v1/login/mock/accepted`).end(function (err) {
if (err) return done(err)
authSession = testSession
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)
})
})
})
......@@ -2,8 +2,7 @@ const mongoose = require('mongoose')
const MentorSchema = new mongoose.Schema({
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'user',
type: String,
required: true,
},
description: {
......
const { app } = require('../../../server')
const session = require('supertest-session')
const { merge, has } = require('lodash')
const { validateKeys } = require('../../../utils/testHelpers')
const { News } = require('../newsModel')
const endpointUrl = '/api/v1/news'
const fakeUserJson = {
internal_id: 'fakeId',
schacc: 'fakeUser',
fullName: 'faker Janos',
secondaryEmail: 'faker@fake.com',
}
let fakeNewsJson={
title:'A legjobb hír',
body:'A legjobb hír ever man!',
creator:'fakeUSer'
}
const defaultKeys={
_id:true,
creator:true,
title:true,
body:true
}
describe('/news "Mentor" Functionality', () => {
let authSession
// Login as mentor
beforeEach(async function (done) {
let testSession = session(app)
testSession.get(`/api/v1/login/mock/mentor`).end(function (err) {
if (err) return done(err)
authSession = testSession
return done()
})})
//readone
test(`GET existing news`, async () => {
const newNews = await News.create(fakeNewsJson)
let response = await authSession.get(`${endpointUrl}/${newNews._id}`)
expect(response.statusCode).toBe(200)
})
test('GET invalid news',async()=>{
let response=await authSession.get(`${endpointUrl}/almafa`)
expect(response.statusCode).toBe(422)
})
// Get Many
test(`GET many returns with allowed keys`, async () => {
await News.create(fakeNewsJson)
await News.create(fakeNewsJson)
let response = await authSession.get(endpointUrl)
expect(response.statusCode).toBe(200)
response.body.data.forEach((eachData) => {
validateKeys(eachData, defaultKeys)
})})
// Create
test(`Create news`, async () => {
const newNews = await News.create(fakeNewsJson)
let response =await authSession.post(`${endpointUrl}/`).send({
title:newNews.title,
body:newNews.body,
creator:newNews.creator,
})
expect(response.statusCode).toBe(201)
validateKeys(response.body.data, defaultKeys)
})
//Update
test(`Update news`,async()=>{
const newNews=await News.create(fakeNewsJson)
let response=await authSession
.put(`${endpointUrl}/${newNews._id}`)
.send({
title:'updatedtitle',
})
expect(response.statusCode).toBe(200)
expect(response.body.data.title).toBe('updatedtitle')
})
//Delete
test(`Delete news`,async ()=>{
const newNews = await News.create(fakeNewsJson)
let response=await authSession.delete(`${endpointUrl}/${newNews._id}`)
expect(response.statusCode).toBe(200)
})
})
describe('/news "Accepted" Functionality',()=>{
let authSession
// Login as accepted
beforeEach(async function (done) {
let testSession = session(app)
testSession.get(`/api/v1/login/mock/accepted`).end(function (err) {
if (err) return done(err)
authSession = testSession
return done()
})})
//readone
test(`GET existing news`, async () => {
const newNews = await News.create(fakeNewsJson)
let response = await authSession.get(`${endpointUrl}/${newNews._id}`)
expect(response.statusCode).toBe(200)
})
test('GET invalid news',async()=>{
let response=await authSession.get(`${endpointUrl}/almafa`)
expect(response.statusCode).toBe(422)
})
// Get Many
test(`GET many returns with allowed keys`, async () => {
await News.create(fakeNewsJson)
await News.create(fakeNewsJson)
let response = await authSession.get(endpointUrl)
expect(response.statusCode).toBe(200)
response.body.data.forEach((eachData) => {
validateKeys(eachData, defaultKeys)
})
})
})
//
const { app } = require('../../../server')
const session = require('supertest-session')
const { merge, has } = require('lodash')
const { validateKeys } = require('../../../utils/testHelpers')
const { User } = require('../../user/userModel')
const {Task}= require('../taskModel')
const endpointUrl = '/api/v1/task'
const fakeUserJson = {
internal_id: 'fakeId',
schacc: 'fakeUser',
fullName: 'faker Janos',
secondaryEmail: 'faker@fake.com',
}
let fakeTaskJson={
title:"The greatest task",
description:'Ezt kell csinálni a greatest tasknál',
deadline:"2020.12.31",
createData:"CreateData",
bit:"10",
}
const defaultKeys={
_id:true,
title:true,
description:true,
deadline:true,
createData:true,
bit:true,
}
describe('/task "Mentor" Functionality', () => {
let authSession
// Login as mentor
beforeEach(async function (done) {
let testSession = session(app)
testSession.get(`/api/v1/login/mock/mentor`).end(function (err) {
if (err) return done(err)
authSession = testSession
return done()
})
})
//readone
test(`GET existing task`, async () => {
const newTask = await Task.create(fakeTaskJson)
let response = await authSession.get(`${endpointUrl}/${newTask._id}`)
expect(response.statusCode).toBe(200)
})
test('GET invalid task',async()=>{
let response=await authSession.get(`${endpointUrl}/almafa`)
expect(response.statusCode).toBe(422)
})
// Get Many
test(`GET many returns with allowed keys`, async () => {
await Task.create(fakeTaskJson)
await Task.create(fakeTaskJson)
let response = await authSession.get(endpointUrl)
expect(response.statusCode).toBe(200)
response.body.data.forEach((eachData) => {
validateKeys(eachData, defaultKeys)
})
})
// Create
test(`Create task`, async () => {
const newTask = await Task.create(fakeTaskJson)
let response =await authSession.post(`${endpointUrl}/`).send({
title:newTask.title,
description:newTask.description,
deadline:newTask.deadline,
createData:newTask.createData,
bit:newTask.bit,
})
expect(response.statusCode).toBe(201)
validateKeys(response.body.data, defaultKeys)
})
//Update
test(`Update task`,async()=>{
const newTask=await Task.create(fakeTaskJson)
let response=await authSession
.put(`${endpointUrl}/${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}`)
expect(response.statusCode).toBe(200)
})
})
//Nem számít az ,hogy melyikkel teszteled mert mind2nak ugyan olyannak kell lennie.
//normal=accepted
describe('/task "Accepted" Functionality', () => {
let authSession
// Login as accepted and create a group
beforeEach(async function (done) {
let testSession = session(app)
testSession.get(`/api/v1/login/mock/accepted`).end(function (err) {
if (err) return done(err)
authSession = testSession
return done()
})
})
//readone
test(`GET existing task`, async () => {
const newTask = await Task.create(fakeTaskJson)
let response = await authSession.get(`${endpointUrl}/${newTask._id}`)
expect(response.statusCode).toBe(200)
})
test('GET invalid task',async()=>{
let response=await authSession.get(`${endpointUrl}/almafa`)
expect(response.statusCode).toBe(422)
})
// Get Many
test(`GET many returns with allowed keys`, async () => {
await Task.create(fakeTaskJson)
await Task.create(fakeTaskJson)
let response = await authSession.get(endpointUrl)
expect(response.statusCode).toBe(200)
response.body.data.forEach((eachData) => {
validateKeys(eachData, defaultKeys)
})
})
})
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