Commit 3e6c2a86 authored by arcter's avatar arcter
Browse files

news functiontest's accepted's tests written

parent cc797910
Pipeline #4667 failed with stages
in 1 minute and 32 seconds
......@@ -33,8 +33,65 @@ let fakeNewsJson={
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}`)
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',
})
expect(response.statusCode).toBe(200)
expect(response.body.data.title).toBe('almafa')
})
})
//
})
//Nem számít az ,hogy melyikkel teszteled mert mind2nak ugyan olyannak kell lennie.
//normal=accepted
......@@ -49,6 +106,39 @@ let fakeNewsJson={
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}`)
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