Skip to content

Commit

Permalink
Merge 23842a7 into 5976365
Browse files Browse the repository at this point in the history
  • Loading branch information
gadishimwe committed Feb 7, 2020
2 parents 5976365 + 23842a7 commit cc66720
Show file tree
Hide file tree
Showing 24 changed files with 126 additions and 14 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"bcrypt": "^3.0.7",
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"faker": "^4.1.0",
Expand Down
3 changes: 2 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import express from 'express';
import morgan from 'morgan';
import passport from 'passport';
import cors from 'cors';
import routes from './routes/index';
import NotificationListeners from './helpers/notifications/index';

const app = express();
app.use(morgan('dev'));

app.use(cors());
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(passport.initialize());
Expand Down
2 changes: 2 additions & 0 deletions src/tests/accomodation/accommodation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import { booking,
newAccomodation,
crateMultipleAccommodations } from '../fixtures/accommodation.fixture';
import { loggedInToken, createUsers } from '../fixtures/users.fixture';
import cleanAllTables from '../fixtures/database.fixture';

chai.should();
chai.use(chaiHttp);

describe('Test booking accommodation:', () => {
before(async () => {
await cleanAllTables();
await createUsers();
await crateMultipleAccommodations();
});
Expand Down
2 changes: 2 additions & 0 deletions src/tests/auth/find-user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
createUsers,
wrongEmail
} from '../fixtures/users.fixture';
import cleanAllTables from '../fixtures/database.fixture';

chai.should();
chai.use(chaiHttp);

describe('/GET find user', () => {
before(async () => {
await cleanAllTables();
await createUsers();
});
it('App should find a user who exists', (done) => {
Expand Down
4 changes: 2 additions & 2 deletions src/tests/auth/google-facebook-auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
googleProfile,
facebookProfile,
OAuthTokens,
cleanDb
} from '../fixtures/users.fixture';
import googleAuthMiddleware from '../../middlewares/google-auth.middleware';
import facebookAuthMiddleware from '../../middlewares/facebook-auth.middleware';
import cleanAllTables from '../fixtures/database.fixture';


chai.use(sinonHttp);
Expand All @@ -21,7 +21,7 @@ describe('Test Google and Facebook authentication:', () => {
const resp = httpMocks.createResponse();
const { accessToken, refreshToken } = OAuthTokens;
before(async () => {
await cleanDb();
await cleanAllTables();
});
afterEach(() => {
sinon.restore();
Expand Down
2 changes: 2 additions & 0 deletions src/tests/auth/login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import {
loggedInToken,
createUsers
} from '../fixtures/users.fixture';
import cleanAllTables from '../fixtures/database.fixture';

chai.use(chaiHttp);

describe('Tests for user login', () => {
before(async () => {
await cleanAllTables();
await createUsers();
});
it('should login a user', (done) => {
Expand Down
2 changes: 2 additions & 0 deletions src/tests/auth/logout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import chaiHttp from 'chai-http';
import chai, { expect } from 'chai';
import app from '../../app';
import { loggedInToken, createUsers } from '../fixtures/users.fixture';
import cleanAllTables from '../fixtures/database.fixture';

chai.use(chaiHttp);
describe('Tests for user logout', () => {
before(async () => {
await cleanAllTables();
await createUsers();
});
it('Should logout a user', (done) => {
Expand Down
2 changes: 2 additions & 0 deletions src/tests/auth/reset-password.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import {
createUsers,
wrongToken,
} from '../fixtures/users.fixture';
import cleanAllTables from '../fixtures/database.fixture';

chai.should();
chai.use(chaiHttp);

describe('/PUT reset password', () => {
before(async () => {
await cleanAllTables();
await createUsers();
});
it('App should reset password', (done) => {
Expand Down
6 changes: 3 additions & 3 deletions src/tests/auth/signup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import {
signedUpUserToken,
signupExpiredToken,
unregisteredEmail,
wrongToken,
cleanDb
wrongToken
} from '../fixtures/users.fixture';
import cleanAllTables from '../fixtures/database.fixture';

chai.use(chaiHttp);
chai.should();

describe('Test for User Signup:', () => {
before(async () => {
await cleanDb();
await cleanAllTables();
});
it('It should create a new user', (done) => {
chai.request(app)
Expand Down
32 changes: 32 additions & 0 deletions src/tests/fixtures/database.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import models from '../../models';

const {
Accommodation,
AddOnServices,
Amenities,
Booking,
Comments,
Image,
Notifications,
Preferences,
Request,
Rooms,
Trip,
Users } = models;

const cleanAllTables = async () => {
await Accommodation.destroy({ where: {} });
await AddOnServices.destroy({ where: {} });
await Amenities.destroy({ where: {} });
await Booking.destroy({ where: {} });
await Comments.destroy({ where: {} });
await Image.destroy({ where: {} });
await Notifications.destroy({ where: {} });
await Preferences.destroy({ where: {} });
await Request.destroy({ where: {} });
await Rooms.destroy({ where: {} });
await Trip.destroy({ where: {} });
await Users.destroy({ where: {} });
};

export default cleanAllTables;
37 changes: 35 additions & 2 deletions src/tests/fixtures/trip.fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,23 @@ const { Trip, Request } = models;
export const invalidId = faker.lorem.word();
export const tripIdNotExists = faker.random.number({ min: 200, max: 200 });

const today = new Date();
const desiredDeparture = new Date();
desiredDeparture.setDate(today.getDate() + 2);
const desiredReturn = new Date();
desiredReturn.setDate(desiredDeparture.getDate() + 5);

const newDate = (date) => {
const dd = String(date.getDate()).padStart(2, '0');
const mm = String(date.getMonth() + 1).padStart(2, '0');
const yyyy = date.getFullYear();
return `${yyyy}-${mm}-${dd}`;
};
export const trip = {
originId: faker.random.number({ min: 1, max: 9 }),
destinationId: faker.random.number({ min: 1, max: 9 }),
departureDate: '2020-02-02',
returnDate: '2020-02-15',
departureDate: newDate(desiredDeparture),
returnDate: newDate(desiredReturn),
travelReasons: faker.lorem.sentence(),
accommodationId: faker.random.number()
};
Expand Down Expand Up @@ -76,6 +88,27 @@ export const createTrip = async () => {
return dataValues;
};


const generatedTrip = {
id: faker.random.number({ min: 100000, max: 100020 }),
userId: loggedInUser.id,
requestId: faker.random.number(),
tripType: 'one-way',
originId: faker.random.number({ min: 1, max: 2 }),
destinationId: faker.random.number({ min: 1, max: 2 }),
departureDate: faker.date.future(),
travelReasons: faker.lorem.sentence(),
accommodationId: faker.random.number()
};


export const createTrip2 = async () => {
const request = await Request.create({ requesterId: generatedTrip.userId, status: 'pending' });
const requestId = request.get().id;
const { dataValues } = await Trip.create({ ...generatedTrip, requestId });
return dataValues;
};

export const formatDate = () => {
const fakerDate = new Date(newTripComment.departureDate);
const month = (`0${fakerDate.getMonth() + 1}`).slice(-2);
Expand Down
2 changes: 2 additions & 0 deletions src/tests/location/location.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import chai, { expect } from 'chai';
import chaiHttp from 'chai-http';
import app from '../../app';
import { loggedInToken, createUsers } from '../fixtures/users.fixture';
import cleanAllTables from '../fixtures/database.fixture';

chai.should();
chai.use(chaiHttp);

describe('Test getting locations:', () => {
before(async () => {
await cleanAllTables();
await createUsers();
});
it('Should return status code of 200 with all available locations', (done) => {
Expand Down
4 changes: 4 additions & 0 deletions src/tests/notification/notification.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import {
loggedInToken2,
token,
} from '../fixtures/users.fixture';
import cleanAllTables from '../fixtures/database.fixture';

chai.use(chaiHttp);

describe('Mark all notifications as read', () => {
beforeEach(async () => {
await cleanAllTables();
await createUsers();
await createNotifications();
});
Expand Down Expand Up @@ -44,6 +46,7 @@ describe('Mark all notifications as read', () => {

describe('Mark notifications as read', () => {
beforeEach(async () => {
await cleanAllTables();
await createUsers();
await createNotifications();
});
Expand Down Expand Up @@ -99,6 +102,7 @@ describe('Tests notification preferences', () => {
const date = (`0${fakerDate.getDate()}`).slice(-2);
const formattedDate = `${fakerDate.getFullYear()}-${month}-${date}`;
beforeEach(async () => {
await cleanAllTables();
await createUsers();
});
it('Should get all notification of a logged in user', (done) => {
Expand Down
2 changes: 2 additions & 0 deletions src/tests/profile/profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import chai from 'chai';
import chaiHttp from 'chai-http';
import app from '../../app';
import { loggedInToken, createUsers, wrongToken, userData } from '../fixtures/users.fixture';
import cleanAllTables from '../fixtures/database.fixture';

chai.use(chaiHttp);
chai.should();

describe('Test for User Account Profile:', () => {
before(async () => {
await cleanAllTables();
await createUsers();
});
it('It should allow user to view profile', (done) => {
Expand Down
3 changes: 3 additions & 0 deletions src/tests/request/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import app from '../../app';
import { managerToken1, managerToken2, nonManagerToken, createManagers } from '../fixtures/managers.fixture';
import { createUsers } from '../fixtures/users.fixture';
import createRequests from '../fixtures/request.fixture';
import cleanAllTables from '../fixtures/database.fixture';

chai.should();
chai.use(chaiHttp);

describe('Test getting request to a manager:', () => {
before(async () => {
await cleanAllTables();
await createUsers();
await createManagers();
await createRequests();
Expand All @@ -33,6 +35,7 @@ describe('Test getting request to a manager:', () => {
describe('Test approving or rejecting a request:', () => {
let request;
before(async () => {
await cleanAllTables();
request = await createRequests();
});
it('Should return status code of 200 on successful request rejection', (done) => {
Expand Down
2 changes: 2 additions & 0 deletions src/tests/search/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import app from '../../app';
import { managerToken1, nonManagerToken, loggedInManager2 } from '../fixtures/managers.fixture';
import createRequests from '../fixtures/request.fixture';
import { createTrip, formatDate } from '../fixtures/trip.fixture';
import cleanAllTables from '../fixtures/database.fixture';

chai.should();
chai.use(chaiHttp);

describe('Test searching requests:', () => {
before(async () => {
await cleanAllTables();
await createRequests();
await createTrip();
});
Expand Down
7 changes: 4 additions & 3 deletions src/tests/settings/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ import {
createUsers,
newRoleData,
loggedInToken,
newUserEmail,
cleanDb
newUserEmail
} from '../fixtures/users.fixture';
import { loggedInManager1, loggedInNonManager, loggedInNonManager2, superAdminToken1, createManagers } from '../fixtures/managers.fixture';
import cleanAllTables from '../fixtures/database.fixture';

chai.use(chaiHttp);
chai.should();

describe('Test for super admin reset user role:', () => {
before(async () => {
await cleanAllTables();
await createUsers();
});
it('It should allow Super-Admin user to reset user role', (done) => {
Expand Down Expand Up @@ -79,7 +80,7 @@ describe('Test for super admin reset user role:', () => {

describe('Test assigning requester to manager', () => {
before(async () => {
await cleanDb();
await cleanAllTables();
await createManagers();
});
it('Should return 200 response when super-adimn assign requester to manager', (done) => {
Expand Down
2 changes: 2 additions & 0 deletions src/tests/trip/comments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import app from '../../app';
import { loggedInToken, userWithNoTripToken, loggedInUser, tokenOfNotAllowedManager, createUsers } from '../fixtures/users.fixture';
import { newComment, badRequest, noTripFound } from '../fixtures/comments.fixture';
import { createTrip } from '../fixtures/trip.fixture';
import cleanAllTables from '../fixtures/database.fixture';

chai.should();
chai.use(chaiHttp);

describe('/POST create comment on trip request', () => {
let trip;
before(async () => {
await cleanAllTables();
await createUsers();
trip = await createTrip();
});
Expand Down
Loading

0 comments on commit cc66720

Please sign in to comment.