Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This file contains code that is sourced from
- //https://pastebin.com/pg0kkdU9 , author:Mr Kushira
- //------------------------------------
- //Basic config
- const SERVER_URL = 'http://localhost:3001';
- //sample data
- const SAMPLE_USERNAME = 'test123';
- const SAMPLE_PASSWORD = 'test123';
- const SAMPLE_POSTID = '597ebeb24317393af33076a2';
- const CORRUPT_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QxMjMiLCJpYXQiOjE1MDEzOTQyOmV4cCI6MTUwMTU2NzA5M30.4mzC72AqPBY0JGf3_uCOymFQd72h0g2wPPlil3r6-38';
- //-----------------------
- const should = require('should');
- const request = require('supertest');
- const agent = request.agent(SERVER_URL);
- describe('testing api calls', () => {
- it('should login when valid details are given', done => {
- agent.post('/users/login')
- .send({
- 'username': SAMPLE_USERNAME,
- 'password': SAMPLE_PASSWORD
- })
- .expect(200)
- .end((err, res) => {
- if (err) {
- return done(err);
- }
- res.body.should.be.an.Object().and.have.property('access_token');
- done();
- });
- });
- it('should reject invalid user tokens', done => {
- agent.post('/isloggedin')
- .set('authorization', 'JWT ' + CORRUPT_TOKEN)
- .send('')
- .expect(401)
- .end((err, res) => {
- if (err) {
- return done(err);
- }
- done();
- });
- });
- it('should return all public posts by a uesr', done => {
- agent.get('/users/' + SAMPLE_USERNAME + '/posts/')
- .expect(200)
- .end((err, res) => {
- if (err) {
- return done(err);
- }
- res.body.should.be.an.Object().and.have.property('posts');
- done();
- });
- });
- it('should return a public post by a user', done => {
- agent.get('/users/' + SAMPLE_USERNAME + '/posts/' + SAMPLE_POSTID)
- .expect(200)
- .end((err, res) => {
- if (err) {
- return done(err);
- }
- res.body.should.be.an.Object().and.have.property('posts');
- done();
- });
- });
- it('should disallow an unathorized user to post activities', done => {
- agent.post('/newactivity')
- .expect(401)
- .set('authorization', 'JWT ' + CORRUPT_TOKEN)
- .end((err, res) => {
- if (err) {
- return done(err);
- }
- done();
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement