Commit 3515ad79 authored by arcter's avatar arcter
Browse files

news's mentortest (create,update, delete)

parent 3e6c2a86
Pipeline #4675 failed with stages
in 3 minutes and 6 seconds
......@@ -15,6 +15,7 @@ const fakeUserJson = {
let fakeNewsJson={
title:'A legjobb hír',
body:'A legjobb hír ever man!',
creator:'fakeUSer'
}
const defaultKeys={
_id:true,
......@@ -32,113 +33,82 @@ let fakeNewsJson={
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 ID`, async () => {
let response = await authSession.get(`${endpointUrl}/almafa`)
expect(response.statusCode).toBe(422)})
//readall
test(`GET many`, async () => {
const newUser1 = await User.create(fakeUserJson)
const newUser2 = await User.create(fakeUserJson)
await News.create(
Object.assign({}, fakeNewsJson, {
creator: newUser1._id,
})
)
await News.create(
Object.assign({}, fakeNewsJson, {
creator: newUser2._id,
})
)
let response = await authSession.get(`${endpointUrl}`)
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 ownUser = await authSession.get('/api/v1/extra/me')
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(200)
expect(response.body.data.length).toBe(2)
response.body.data.forEach((eachData) => {
validateKeys(eachData, defaultKeys)
})
})
// Create
test(`Create returns with allowed keys`, async () => {
let response = await authSession.post(endpointUrl).send(fakeNewsJson)
expect(response.statusCode).toBe(201)
validateKeys(response.body.data, defaultKeys)
})
// Delete
test(`Delete returns with allowed keys`, async () => {
const newNews = await News.create(fakeNewsJson)
let response = await authSession.delete(`${endpointUrl}/${newNews._id}`)
expect(response.statusCode).toBe(200)
validateKeys(response.body.data, defaultKeys)
})
// Update
test(`Update returns with allowed keys`, async () => {
const newNews = await News.create(fakeNewsJson)
let response = await authSession
.put(`${endpointUrl}/${newNews._id}`).send({
title: 'almafa',
})
//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('almafa')
expect(response.body.data.title).toBe('updatedtitle')
})
})
//
})
//Nem számít az ,hogy melyikkel teszteled mert mind2nak ugyan olyannak kell lennie.
//normal=accepted
describe('/news "Accepted" Functionality', () => {
describe('/news "Accepted" Functionality',()=>{
let authSession
// Login as accepted and create a group
// 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
})})
//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 ID`, async () => {
let response = await authSession.get(`${endpointUrl}/almafa`)
expect(response.statusCode).toBe(422)})
//readall
test(`GET many`, async () => {
const newUser1 = await User.create(fakeUserJson)
const newUser2 = await User.create(fakeUserJson)
await News.create(
Object.assign({}, fakeNewsJson, {
creator: newUser1._id,
})
)
await News.create(
Object.assign({}, fakeNewsJson, {
creator: newUser2._id,
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)
})
)
let response = await authSession.get(`${endpointUrl}`)
expect(response.statusCode).toBe(200)
expect(response.body.data.length).toBe(2)
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