Skip to content

Commit

Permalink
🎧 User can view single post
Browse files Browse the repository at this point in the history
  • Loading branch information
tochiOz committed Apr 8, 2020
1 parent 0ac4491 commit dbbdd39
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
37 changes: 37 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,40 @@ response
}
}
```

### Query A SINGLE POST
request
```javascript
{
getOneNewsletter(id: 8){
id
title
headerImage
excerpt
slug
author
content
createdAt
updatedAt
}
}

```
response
```json
{
"data": {
"getOneNewsletter": {
"id": 8,
"title": "Testing Documentary",
"headerImage": "www.headerImage.com/image.jpg",
"excerpt": "<p>Designing Api Architecture</p>\n",
"slug": "testing-documentary",
"author": "Tochi",
"content": "<h1>NewsLetter Documentary</h1>\n",
"createdAt": "2020-04-08",
"updatedAt": "2020-04-08"
}
}
}
```
73 changes: 73 additions & 0 deletions src/test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,79 @@ describe('Edit Post', () => {
});
});


describe('Users Can View a single Post', () => {
it('Users can display a single post in the database without token', async () => {
const response = await chai
.request(server)
.post('/graphql')
.send({
query: `query {
getOneNewsletter(id:${postId}){
id
title
headerImage
excerpt
slug
author
content
createdAt
updatedAt
}
}`
});
expect(response).to.have.status(200);
expect(response.body.data).to.be.a('object');
});
it('Admin can display a single post in the database with token', async () => {
const response = await chai
.request(server)
.post('/graphql')
.set('Cookie', `token=${token}`)
.send({
query: `query {
getOneNewsletter(id:${postId}){
id
title
headerImage
excerpt
slug
author
content
createdAt
updatedAt
}
}`
});
expect(response).to.have.status(200);
expect(response.body.data).to.be.a('object');
});
it('should fail if post is not found', async () => {
const response = await chai
.request(server)
.post('/graphql')
.send({
query: `query {
getOneNewsletter(id: 5){
id
title
headerImage
excerpt
slug
author
content
createdAt
updatedAt
}
}`
});
expect(response).to.have.status(404);
expect(response.body.errors).to.be.a('array');
expect(response.body.errors[0].message).to.be.a('string');
expect(response.body.errors[0].message).to.eql('Post Not Found!!');
});
});

describe('Delete Post', () => {
it('should fail to delete a post if admin token is absent', async () => {
const response = await chai
Expand Down

0 comments on commit dbbdd39

Please sign in to comment.