Skip to content

Commit

Permalink
fix(scheduler-service): add filter related changes, add relation cont…
Browse files Browse the repository at this point in the history
…rollers (#34)

add filter intake capabilities to listing APIs, add-relation controller, add and update acceptance
SFO-89, SFO-80
  • Loading branch information
rashisf authored Jun 25, 2020
1 parent ae28530 commit 230fd05
Show file tree
Hide file tree
Showing 17 changed files with 1,123 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ describe('Calendar Event Controller', () => {
.expect(200);
});

it('gives status 200 when filter is passed', async () => {
await client
.get(`/calendars/${calendarId}/events?filter[where][deleted]=false`)
.set('authorization', `Bearer ${token}`)
.expect(200);
});

it('gives status 200 when valid min max times are passed as query parameters', async () => {
const timeMin = new Date(2020, 6, 12).toISOString();
const timeMax = new Date(2020, 6, 13).toISOString();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import {Client, expect} from '@loopback/testlab';
import * as jwt from 'jsonwebtoken';
import {CalendarRepository} from '../../repositories';
import {SchedulerApplication} from '../application';
import {setUpApplication} from './helper';

describe('Calendar-Subscription Controller', () => {
let app: SchedulerApplication;
let client: Client;
let calendarRepo: CalendarRepository;
let calendarId: string;

const pass = 'test_password';
const testUser = {
id: 1,
username: 'test_user',
password: pass,
permissions: [
'ViewSubscription',
'CreateSubscription',
'UpdateSubscription',
'DeleteSubscription',
'CreateCalendar',
'ViewCalendar',
],
};

const token = jwt.sign(testUser, 'kdskssdkdfs', {
expiresIn: 180000,
issuer: 'sf',
});

before('setupApplication', async () => {
({app, client} = await setUpApplication());
});
after(async () => app.stop());

before(givenRepositories);
afterEach(deleteMockData);
before(setUpMockData);

it('gives status 422 when data sent is incorrect', async () => {
const reqData = {invalid: 'dummy'};
const response = await client
.post(`/calendars/${calendarId}/subscriptions`)
.set('authorization', `Bearer ${token}`)
.send(reqData)
.expect(422);

expect(response).to.have.property('error');
});

it('gives status 401 when no token is passed', async () => {
const response = await client
.get(`/calendars/${calendarId}/subscriptions`)
.expect(401);

expect(response).to.have.property('error');
});

it('gives status 200 when token is passed', async () => {
await client
.get(`/calendars/${calendarId}/subscriptions`)
.set('authorization', `Bearer ${token}`)
.expect(200);
});

it('gives status 422 when subscription details are not correct', async () => {
const subscriptionToAdd = {invalid: 'dummy'};

await client
.post(`/calendars/${calendarId}/subscriptions`)
.set('authorization', `Bearer ${token}`)
.send(subscriptionToAdd)
.expect(422);
});

it('deletes subscriptions belonging to a calendarId successfully', async () => {
await client
.del(`/calendars/${calendarId}/subscriptions`)
.set('authorization', `Bearer ${token}`)
.expect(200);
});

it('updates subscriptions belonging to a calendarId successfully', async () => {
const response = await client
.patch(`/calendars/${calendarId}/subscriptions`)
.set('authorization', `Bearer ${token}`)
.send({isHidden: true})
.expect(200);
expect(response.body).to.have.properties('count');
});

async function setUpMockData() {
const calendar = await client
.post(`/calendars`)
.set('authorization', `Bearer ${token}`)
.send({identifier: 'dummy'});

calendarId = calendar.body.id;

await client
.post(`/calendars/${calendarId}/subscriptions`)
.set('authorization', `Bearer ${token}`)
.send({identifier: 'dummy'});
}

async function deleteMockData() {
await calendarRepo.deleteAllHard();
}

async function givenRepositories() {
calendarRepo = await app.getRepository(CalendarRepository);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import {Client, expect} from '@loopback/testlab';
import * as jwt from 'jsonwebtoken';
import {CalendarRepository} from '../../repositories';
import {SchedulerApplication} from '../application';
import {setUpApplication} from './helper';

describe('Calendar-WorkingHour Controller', () => {
let app: SchedulerApplication;
let client: Client;
let calendarRepo: CalendarRepository;
let calendarId: string;

const pass = 'test_password';
const testUser = {
id: 1,
username: 'test_user',
password: pass,
permissions: [
'ViewWorkingHour',
'CreateWorkingHour',
'UpdateWorkingHour',
'DeleteWorkingHour',
'CreateCalendar',
'ViewCalendar',
],
};

const token = jwt.sign(testUser, 'kdskssdkdfs', {
expiresIn: 180000,
issuer: 'sf',
});

before('setupApplication', async () => {
({app, client} = await setUpApplication());
});
after(async () => app.stop());

before(givenRepositories);
afterEach(deleteMockData);
before(setUpMockData);

it('gives status 422 when data sent is incorrect', async () => {
const reqData = {invalid: 'dummy'};
const response = await client
.post(`/calendars/${calendarId}/working-hours`)
.set('authorization', `Bearer ${token}`)
.send(reqData)
.expect(422);

expect(response).to.have.property('error');
});

it('gives status 401 when no token is passed', async () => {
const response = await client
.get(`/calendars/${calendarId}/working-hours`)
.expect(401);

expect(response).to.have.property('error');
});

it('gives status 200 when token is passed', async () => {
await client
.get(`/calendars/${calendarId}/working-hours`)
.set('authorization', `Bearer ${token}`)
.expect(200);
});

it('gives status 422 when workingHour details are not correct', async () => {
const workingHourToAdd = {invalid: 'dummy'};

await client
.post(`/calendars/${calendarId}/working-hours`)
.set('authorization', `Bearer ${token}`)
.send(workingHourToAdd)
.expect(422);
});

it('deletes working-hours belonging to a calendarId successfully', async () => {
await client
.del(`/calendars/${calendarId}/working-hours`)
.set('authorization', `Bearer ${token}`)
.expect(200);
});

it('updates working-hours belonging to a calendarId successfully', async () => {
const response = await client
.patch(`/calendars/${calendarId}/working-hours`)
.set('authorization', `Bearer ${token}`)
.send({dayOfWeek: 1})
.expect(200);
expect(response.body).to.have.properties('count');
});

async function setUpMockData() {
const calendar = await client
.post(`/calendars`)
.set('authorization', `Bearer ${token}`)
.send({identifier: 'dummy'});

calendarId = calendar.body.id;

await client
.post(`/calendars/${calendarId}/working-hours`)
.set('authorization', `Bearer ${token}`)
.send({identifier: 'dummy'});
}

async function deleteMockData() {
await calendarRepo.deleteAllHard();
}

async function givenRepositories() {
calendarRepo = await app.getRepository(CalendarRepository);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import {Client, expect} from '@loopback/testlab';
import * as jwt from 'jsonwebtoken';
import {EventRepository} from '../../repositories';
import {SchedulerApplication} from '../application';
import {setUpApplication} from './helper';

describe('Event-Attachment Controller', () => {
let app: SchedulerApplication;
let client: Client;
let eventRepo: EventRepository;
let eventId: string;

const pass = 'test_password';
const testUser = {
id: 1,
username: 'test_user',
password: pass,
permissions: [
'ViewAttachment',
'CreateAttachment',
'UpdateAttachment',
'DeleteAttachment',
'CreateEvent',
'ViewEvent',
],
};

const token = jwt.sign(testUser, 'kdskssdkdfs', {
expiresIn: 180000,
issuer: 'sf',
});

before('setupApplication', async () => {
({app, client} = await setUpApplication());
});
after(async () => app.stop());

before(givenRepositories);
afterEach(deleteMockData);
before(setUpMockData);

it('gives status 422 when data sent is incorrect', async () => {
const reqData = {invalid: 'dummy'};
const response = await client
.post(`/events/${eventId}/attachments`)
.set('authorization', `Bearer ${token}`)
.send(reqData)
.expect(422);

expect(response).to.have.property('error');
});

it('gives status 401 when no token is passed', async () => {
const response = await client
.get(`/events/${eventId}/attachments`)
.expect(401);

expect(response).to.have.property('error');
});

it('gives status 200 when token is passed', async () => {
await client
.get(`/events/${eventId}/attachments`)
.set('authorization', `Bearer ${token}`)
.expect(200);
});

it('gives status 422 when attachment details are not correct', async () => {
const attachmentToAdd = {invalid: 'dummy'};

await client
.post(`/events/${eventId}/attachments`)
.set('authorization', `Bearer ${token}`)
.send(attachmentToAdd)
.expect(422);
});

it('deletes attachments belonging to a eventId successfully', async () => {
await client
.del(`/events/${eventId}/attachments`)
.set('authorization', `Bearer ${token}`)
.expect(200);
});

it('updates attachments belonging to a eventId successfully', async () => {
const response = await client
.patch(`/events/${eventId}/attachments`)
.set('authorization', `Bearer ${token}`)
.send({fileUrl: 'dummy'})
.expect(200);
expect(response.body).to.have.properties('count');
});

async function setUpMockData() {
const event = await client
.post(`/events`)
.set('authorization', `Bearer ${token}`)
.send({identifier: 'dummy'});

eventId = event.body.id;

await client
.post(`/events/${eventId}/attachments`)
.set('authorization', `Bearer ${token}`)
.send({identifier: 'dummy'});
}

async function deleteMockData() {
await eventRepo.deleteAllHard();
}

async function givenRepositories() {
eventRepo = await app.getRepository(EventRepository);
}
});
Loading

0 comments on commit 230fd05

Please sign in to comment.