-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { User } from '../models'; | ||
|
||
const getAuthors = async (req, res) => { | ||
try { | ||
const authors = User.findAll({ | ||
where: { role: 'author' }, | ||
}); | ||
|
||
if (authors) { | ||
res.status(200).json({ status: 'success', data: authors }); | ||
} | ||
|
||
if (authors.length === 0) { | ||
res.status(200).json({ status: 'success', message: 'The is no Author on the database' }); | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
export default getAuthors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import chai from 'chai'; | ||
import chaiHttp from 'chai-http'; | ||
import { startServer } from '../../src/server'; | ||
import LOGIN from '../mock/login'; | ||
|
||
const { expect } = chai; | ||
let app = null; | ||
let agent = null; | ||
let userToken; | ||
|
||
chai.use(chaiHttp); | ||
|
||
describe('LIST AUTHORS', () => { | ||
beforeEach(async () => { | ||
app = await startServer(6600); | ||
agent = chai.request(app); | ||
}); | ||
it('login User', (done) => { | ||
agent | ||
.post('/api/v1/login') | ||
.send(LOGIN) | ||
.end((err, res) => { | ||
const { token } = res.body.data; | ||
userToken = token; | ||
done(); | ||
}); | ||
}); | ||
it('should list authors', (done) => { | ||
const jwt = `Bearer ${userToken}`; | ||
agent | ||
.get('/api/v1/authors') | ||
.set('Authorization', jwt) | ||
.end((err, res) => { | ||
expect(res.statusCode).to.equal(200); | ||
done(); | ||
}); | ||
}); | ||
}); |