TT#31803 Remove time from timeset

What has been done:
- TT#32221, CallForwarding: Implement UI icons and flow
- TT#32222, CallForwarding: Implement store and state management
- TT#31808, CallForwarding: Implement api requests

Change-Id: I0fd13e129ee006b7b08333df7a386de12710266a
changes/52/18852/12
raxelsen 7 years ago committed by Robert Axelsen
parent f345683357
commit 3a2f7bd30f

@ -380,8 +380,8 @@ export function moveDestinationDown(options) {
} }
export function getDaysFromRange(options) { export function getDaysFromRange(options) {
let fromDay = options.from; let fromDay = options.fromDay;
let toDay = options.to; let toDay = options.toDay + 1;
let wdayMap = { let wdayMap = {
1: i18n.t('pages.callForward.times.sunday'), 1: i18n.t('pages.callForward.times.sunday'),
2: i18n.t('pages.callForward.times.monday'), 2: i18n.t('pages.callForward.times.monday'),
@ -393,29 +393,31 @@ export function getDaysFromRange(options) {
}; };
let days = []; let days = [];
while (fromDay < toDay) { while (fromDay < toDay) {
days.push({ name: wdayMap[fromDay], number: fromDay }); days.push({ name: wdayMap[fromDay], number: fromDay.toString() });
fromDay++; fromDay++;
}; };
return days; return days;
} }
export function getHoursFromRange(options) { export function getHoursFromRange(options) {
let toHour = options.toHour + 1;
let fromMinute = options.hasMinute ? options.fromMinute : '00'; let fromMinute = options.hasMinute ? options.fromMinute : '00';
let toMinute = options.hasMinute ? options.toMinute + 1 : '00'; let toMinute = options.hasMinute ? options.toMinute + 1 : '00';
toMinute = !toMinute ? fromMinute + 1 : toMinute; toMinute = !toMinute ? fromMinute + 1 : toMinute;
let hours = []; let hours = [];
if (options.hasMinute) { if (options.hasMinute) {
while (options.fromHour < options.toHour) { while (options.fromHour < toHour) {
hours.push({ hours.push({
from: `${options.fromHour}:${fromMinute}`, from: `${options.fromHour}:${fromMinute}`,
to: `${options.fromHour}:${toMinute}` to: `${options.fromHour}:${toMinute}`,
hour: options.fromHour.toString()
}); });
options.fromHour++; options.fromHour++;
}; };
} else { } else {
hours.push({ hours.push({
from: `${options.fromHour}:${fromMinute}`, from: `${options.fromHour}:${fromMinute}`,
to: `${options.toHour}:${toMinute}` to: `${toHour}:${toMinute}`
}); });
} }
return hours; return hours;
@ -424,48 +426,54 @@ export function getHoursFromRange(options) {
export function convertTimesetToWeekdays(options) { export function convertTimesetToWeekdays(options) {
let times = []; let times = [];
let counter = 0; let counter = 0;
let timesetIsCompatible = false; let timesetIsCompatible = true;
let timesetHasDuplicate = false; let timesetHasDuplicate = false;
let timesetExists = false; let timesetExists = false;
let timesetHasReverse = false; let timesetHasReverse = false;
let timesetId = null;
options.timesets.forEach((timeset) => { options.timesets.forEach((timeset) => {
let timesetNameMatches = timeset.name === options.timesetName; let timesetNameMatches = timeset.name === options.timesetName;
if (counter === 0 && timesetNameMatches) { if (counter === 0 && timesetNameMatches) {
timeset.times.forEach((time) => { timeset.times.forEach((time) => {
let days = []; let isIncompatible = time.mday || time.month || time.year || !time.wday || !time.hour;
let hours = []; if (isIncompatible) {
let fromDay = parseInt(time.wday.split('-')[0]);
let toDay = time.wday.split('-')[1] ? parseInt(time.wday.split('-')[1]) + 1 : fromDay + 1;
let fromHour = parseInt(time.hour.split('-')[0]);
let toHour = time.hour.split('-')[1] ? parseInt(time.hour.split('-')[1]) + 1 : fromHour + 1;
let fromMinute = time.minute ? parseInt(time.minute.split('-')[0]) : undefined;
let toMinute = (time.minute && time.minute.split('-')[1]) ? parseInt(time.minute.split('-')[1]) : undefined;
let isCompatible = time.mday || time.month || time.year || !time.wday || !time.hour;
let isReverse = fromDay > toDay || fromHour > toHour || fromMinute > toMinute;
if (isCompatible) {
timesetIsCompatible = false; timesetIsCompatible = false;
return; return;
} else if (isReverse) { } else {
timesetHasReverse = true; let days = [];
return; let hours = [];
} else { let fromDay = parseInt(time.wday.split('-')[0]);
hours = getHoursFromRange({ hasMinute: !!time.minute, let toDay = time.wday.split('-')[1] ? parseInt(time.wday.split('-')[1]) : fromDay;
fromHour: fromHour, toHour: toHour, let fromHour = parseInt(time.hour.split('-')[0]);
fromMinute: fromMinute, toMinute: toMinute }); let toHour = time.hour.split('-')[1] ? parseInt(time.hour.split('-')[1]) : fromHour;
days = getDaysFromRange({ from: fromDay, to: toDay }); let fromMinute = time.minute ? parseInt(time.minute.split('-')[0]) : undefined;
days.forEach(day => { let toMinute = (time.minute && time.minute.split('-')[1]) ? parseInt(time.minute.split('-')[1]) : undefined;
hours.forEach(hour => { let isReverse = fromDay > toDay || fromHour > toHour || fromMinute > toMinute;
times.push({ let timesHour;
weekday: day.name, if (isReverse) {
from: hour.from, timesetHasReverse = true;
to: hour.to, return;
wday: time.wday, } else {
hour: time.hour, hours = getHoursFromRange({ hasMinute: !!time.minute,
minute: time.minute fromHour: fromHour, toHour: toHour,
fromMinute: fromMinute, toMinute: toMinute });
days = getDaysFromRange({ fromDay: fromDay, toDay: toDay });
days.forEach(day => {
hours.forEach(hour => {
timesHour = time.minute ? hour.hour : time.hour;
times.push({
weekday: day.name,
from: hour.from,
to: hour.to,
wday: day.number,
hour: timesHour,
minute: time.minute
});
}); });
}); });
}); timesetId = timeset.id;
timesetIsCompatible = true; timesetIsCompatible = true;
}
} }
}); });
timesetExists = true; timesetExists = true;
@ -480,7 +488,8 @@ export function convertTimesetToWeekdays(options) {
timesetIsCompatible: timesetIsCompatible, timesetIsCompatible: timesetIsCompatible,
timesetExists: timesetExists, timesetExists: timesetExists,
timesetHasReverse: timesetHasReverse, timesetHasReverse: timesetHasReverse,
timesetHasDuplicate: timesetHasDuplicate timesetHasDuplicate: timesetHasDuplicate,
timesetId: timesetId
}; };
} }
@ -498,3 +507,30 @@ export function loadTimesetTimes(options) {
}); });
}); });
} }
export function deleteTimeFromTimeset(options) {
let headers = {
'Content-Type': 'application/json-patch+json'
};
return new Promise((resolve, reject) => {
Vue.http.patch('/api/cftimesets/' + options.timesetId, [{
op: 'replace',
path: '/times',
value: options.times
}], { headers: headers }).then((result) => {
resolve(result);
}).catch(err => {
reject(err);
});
});
}
export function deleteTimesetById(id) {
return new Promise((resolve, reject) => {
Vue.http.delete('/api/cftimesets/' + id).then(() => {
resolve();
}).catch(err => {
reject(err);
});
});
}

@ -1,6 +1,6 @@
<template> <template>
<csc-page :title="$t('pages.callForward.titles.always')"> <csc-page :title="$t('pages.callForward.titles.always')">
<csc-call-forward-destinations timeset="null" :destinations="destinations"> <csc-call-forward-destinations :timeset="alwaysTimeset" :destinations="destinations">
</csc-call-forward-destinations> </csc-call-forward-destinations>
</csc-page> </csc-page>
</template> </template>
@ -23,7 +23,10 @@
computed: { computed: {
...mapState('callForward', [ ...mapState('callForward', [
'destinations' 'destinations'
]) ]),
alwaysTimeset() {
return null;
}
} }
} }
</script> </script>

@ -5,31 +5,31 @@
<csc-call-forward-destinations timeset="Company Hours" :destinations="destinations"> <csc-call-forward-destinations timeset="Company Hours" :destinations="destinations">
</csc-call-forward-destinations> </csc-call-forward-destinations>
</div> </div>
<div v-else-if="timesetHasReverse && timesetExists"> <div v-else-if="timesetHasDuplicate && timesetExists">
<q-alert color="red" <q-alert color="red"
icon="date_range" icon="date_range"
enter="bounceInLeft" enter="bounceInLeft"
leave="bounceOutRight" leave="bounceOutRight"
appear> appear>
{{ $t('pages.callForward.times.companyHoursReverse') }} {{ $t('pages.callForward.times.companyHoursDuplicate') }}
</q-alert> </q-alert>
</div> </div>
<div v-else-if="timesetHasDuplicate && timesetExists"> <div v-else-if="!timesetIsCompatible && timesetExists">
<q-alert color="red" <q-alert color="red"
icon="date_range" icon="date_range"
enter="bounceInLeft" enter="bounceInLeft"
leave="bounceOutRight" leave="bounceOutRight"
appear> appear>
{{ $t('pages.callForward.times.companyHoursDuplicate') }} {{ $t('pages.callForward.times.companyHoursIncompatible') }}
</q-alert> </q-alert>
</div> </div>
<div v-else-if="!timesetIsCompatible && timesetExists"> <div v-else-if="timesetHasReverse && timesetExists">
<q-alert color="red" <q-alert color="red"
icon="date_range" icon="date_range"
enter="bounceInLeft" enter="bounceInLeft"
leave="bounceOutRight" leave="bounceOutRight"
appear> appear>
{{ $t('pages.callForward.times.companyHoursIncompatible') }} {{ $t('pages.callForward.times.companyHoursReverse') }}
</q-alert> </q-alert>
</div> </div>
<div v-else> <div v-else>

@ -23,7 +23,7 @@
<script> <script>
import numberFormat from '../../../filters/number-format' import numberFormat from '../../../filters/number-format'
import { mapState } from 'vuex' import { mapState, mapGetters } from 'vuex'
import { startLoading, stopLoading, import { startLoading, stopLoading,
showGlobalError, showToast } from '../../../helpers/ui' showGlobalError, showToast } from '../../../helpers/ui'
import CscDestinations from './CscDestinations' import CscDestinations from './CscDestinations'
@ -52,18 +52,32 @@
addDestinationError(state) { addDestinationError(state) {
return state.addDestinationError || return state.addDestinationError ||
this.$t('pages.callForward.addErrorMessage'); this.$t('pages.callForward.addErrorMessage');
},
removeTimeState: 'removeTimeState',
lastRemovedDay: 'lastRemovedDay',
removeTimeError(state) {
return state.removeTimeError ||
this.$t('pages.callForward.times.removeErrorMessage');
} }
}),
...mapGetters('callForward', {
timesLength: 'getTimesetTimesLength'
}) })
}, },
methods: { methods: {
reload(timeset) { reloadDestinations(timeset) {
if (!timeset) { if (timeset === null) {
this.$store.dispatch('callForward/loadAlwaysEverybodyDestinations'); this.$store.dispatch('callForward/loadAlwaysEverybodyDestinations');
} else if (timeset === 'Company Hours') { } else if (timeset === 'Company Hours') {
this.$store.dispatch('callForward/loadCompanyHoursEverybodyDestinations'); this.$store.dispatch('callForward/loadCompanyHoursEverybodyDestinations');
} else if (timeset === 'After Hours') { } else if (timeset === 'After Hours') {
this.$store.dispatch('callForward/loadAfterHoursEverybodyDestinations'); this.$store.dispatch('callForward/loadAfterHoursEverybodyDestinations');
}; };
},
reloadTimes(timeset) {
this.$store.dispatch('callForward/loadTimesetTimes', {
timeset: this.timeset
});
} }
}, },
watch: { watch: {
@ -78,7 +92,7 @@
showToast(this.$t('pages.callForward.removeSuccessMessage', { showToast(this.$t('pages.callForward.removeSuccessMessage', {
destination: this.lastRemovedDestination destination: this.lastRemovedDestination
})); }));
this.reload(this.timeset); this.reloadDestinations(this.timeset);
} }
}, },
addDestinationState(state) { addDestinationState(state) {
@ -92,7 +106,7 @@
showToast(this.$t('pages.callForward.addDestinationSuccessMessage', { showToast(this.$t('pages.callForward.addDestinationSuccessMessage', {
destination: this.lastAddedDestination destination: this.lastAddedDestination
})); }));
this.reload(this.timeset); this.reloadDestinations(this.timeset);
} }
}, },
changeDestinationState(state) { changeDestinationState(state) {
@ -103,7 +117,25 @@
showGlobalError(this.changeDestinationError); showGlobalError(this.changeDestinationError);
} else if (state === 'succeeded') { } else if (state === 'succeeded') {
stopLoading(); stopLoading();
this.reload(this.timeset); this.reloadDestinations(this.timeset);
}
},
removeTimeState(state) {
if (state === 'requesting') {
startLoading();
} else if (state === 'failed') {
stopLoading();
showGlobalError(this.removeTimeError);
} else if (state === 'succeeded') {
stopLoading();
if (this.timesLength <= 1) {
showToast(this.$t('pages.callForward.times.removeTimesetSuccessMessage'));
} else {
showToast(this.$t('pages.callForward.times.removeSuccessMessage', {
day: this.lastRemovedDay
}));
}
this.reloadTimes(this.timeset);
} }
} }
} }

@ -1,7 +1,7 @@
<template> <template>
<q-field class="time-field"> <q-field class="time-field">
<div class="row no-wrap"> <div class="row no-wrap">
<q-input class="col-8" <q-input class="col-7"
v-model="weekday" v-model="weekday"
readonly /> readonly />
<q-datetime <q-datetime
@ -20,16 +20,27 @@
type="time" type="time"
format24h format24h
readonly /> readonly />
<q-btn flat
class="col-1"
color="negative"
icon="delete"
@click="deleteTime(index)">
</q-btn>
</div> </div>
</q-field> </q-field>
</template> </template>
<script> <script>
import { QField, QInput, QDatetime, date } from 'quasar-framework' import { QField, QInput, QDatetime, Dialog,
QBtn, Alert, date } from 'quasar-framework'
import { mapGetters } from 'vuex'
import 'quasar-extras/animate/bounceInRight.css'
import 'quasar-extras/animate/bounceOutRight.css'
export default { export default {
name: 'csc-call-forward-time', name: 'csc-call-forward-time',
props: [ props: [
'time' 'time',
'index'
], ],
data () { data () {
return { return {
@ -38,9 +49,14 @@
components: { components: {
QField, QField,
QInput, QInput,
QDatetime QDatetime,
Dialog,
QBtn
}, },
computed: { computed: {
...mapGetters('callForward', {
timesLength: 'getTimesetTimesLength'
}),
weekday() { weekday() {
return this.time.weekday; return this.time.weekday;
}, },
@ -56,6 +72,52 @@
minutes: this.time.to.split(':')[1] minutes: this.time.to.split(':')[1]
}); });
} }
},
methods: {
deleteTime(index) {
let self = this;
let store = this.$store;
if (this.timesLength <= 1) {
Alert.create({
enter: 'bounceInRight',
leave: 'bounceOutRight',
position: 'top-center',
html: self.$t('pages.callForward.times.removeLastDialogText'),
icon: 'warning',
actions: [
{
label: self.$t('buttons.remove'),
handler () {
store.dispatch('callForward/deleteTimesetById')
}
},
{
label: self.$t('buttons.cancel')
}
]
});
} else {
Dialog.create({
title: self.$t('pages.callForward.times.removeDialogTitle'),
message: self.$t('pages.callForward.times.removeDialogText', {
day: self.weekday
}),
buttons: [
self.$t('buttons.cancel'),
{
label: self.$t('buttons.remove'),
color: 'negative',
handler () {
store.dispatch('callForward/deleteTimeFromTimeset', {
index: index,
removedDay: self.weekday
})
}
}
]
});
}
}
} }
} }
</script> </script>

@ -4,12 +4,7 @@
Times Times
</q-card-title> </q-card-title>
<q-card-main> <q-card-main>
<div class="row no-wrap"> <csc-call-forward-time v-if="times.length > 0" v-for="(time, index) in times" :time="time" :index="index">
<p class="col-8 ">{{ $t('pages.callForward.times.weekday') }}</p>
<p class="col-2 hour-label">{{ $t('pages.callForward.times.from') }}</p>
<p class="col-2 hour-label">{{ $t('pages.callForward.times.to') }}</p</p>
</div>
<csc-call-forward-time v-if="times.length > 0" v-for="(time, index) in times" :time="time">
</csc-call-forward-time> </csc-call-forward-time>
</q-card-main> </q-card-main>
<q-card-actions> <q-card-actions>
@ -26,13 +21,13 @@
<script> <script>
import numberFormat from '../../../filters/number-format' import numberFormat from '../../../filters/number-format'
import CscCallForwardTime from './CscCallForwardTime' import CscCallForwardTime from './CscCallForwardTime'
import { mapState } from 'vuex'
import { QCard, QCardTitle, QCardMain, QCardActions, import { QCard, QCardTitle, QCardMain, QCardActions,
QField, QBtn } from 'quasar-framework' QField, QBtn } from 'quasar-framework'
export default { export default {
name: 'csc-call-forward-times', name: 'csc-call-forward-times',
props: [ props: [
'times' 'times',
'timeset'
], ],
data () { data () {
return { return {
@ -63,7 +58,7 @@
padding-left 5px padding-left 5px
padding-bottom 8px padding-bottom 8px
.times-card .times-card
padding 0 15px padding 0 15px
.q-field .q-field
margin 5px 0 margin 5px 0
.q-card-actions .q-card-actions
@ -79,5 +74,5 @@
color $secondary color $secondary
margin-bottom 0 margin-bottom 0
.hour-label .hour-label
text-align right text-align center
</style> </style>

@ -56,8 +56,8 @@
import numberFormat from '../../../filters/number-format' import numberFormat from '../../../filters/number-format'
import _ from 'lodash' import _ from 'lodash'
import { startLoading, stopLoading, import { startLoading, stopLoading,
showGlobalError, showToast } from '../../../helpers/ui' showGlobalError } from '../../../helpers/ui'
import { QItem, QItemMain, QItemSide, Toast, import { QItem, QItemMain, QItemSide,
Dialog, QBtn } from 'quasar-framework' Dialog, QBtn } from 'quasar-framework'
export default { export default {
name: 'csc-destination', name: 'csc-destination',
@ -72,7 +72,6 @@
QItemMain, QItemMain,
QItemSide, QItemSide,
Dialog, Dialog,
Toast,
QBtn QBtn
}, },
computed: { computed: {

@ -151,6 +151,13 @@
"timeout": "Timeout", "timeout": "Timeout",
"destination": "Destination", "destination": "Destination",
"times": { "times": {
"removeDialogTitle": "Remove call forward time",
"removeDialogText": "You are about to remove the time entry for {day}",
"removeLastDialogTitle": "Remove last call forward time",
"removeLastDialogText": "WARNING: Removing the last time entry will also delete this timeset and all corresponding destinations. Are you sure you want to do this?",
"removeSuccessMessage": "Removed time entry for {day}",
"removeErrorMessage": "An error occured while trying to delete the time entry. Please try again.",
"removeTimesetSuccessMessage": "Removed timeset",
"noTimeSet": "no time set", "noTimeSet": "no time set",
"addTimeButton": "Add Time", "addTimeButton": "Add Time",
"companyHoursIncompatible": "The Company Hours timeset contains incompatible values.", "companyHoursIncompatible": "The Company Hours timeset contains incompatible values.",

@ -14,7 +14,9 @@ import { getSourcesets,
changePositionOfDestination, changePositionOfDestination,
moveDestinationUp, moveDestinationUp,
moveDestinationDown, moveDestinationDown,
loadTimesetTimes } from '../api/call-forward'; loadTimesetTimes,
deleteTimeFromTimeset,
deleteTimesetById } from '../api/call-forward';
const DestinationState = { const DestinationState = {
button: 'button', button: 'button',
@ -43,6 +45,9 @@ export default {
lastAddedDestination: null, lastAddedDestination: null,
changeDestinationState: DestinationState.button, changeDestinationState: DestinationState.button,
changeDestinationError: null, changeDestinationError: null,
removeTimeState: DestinationState.button,
removeTimeError: null,
lastRemovedDay: null,
activeForm: '', activeForm: '',
formType: '', formType: '',
destinationsetId: '', destinationsetId: '',
@ -54,10 +59,11 @@ export default {
timeout: '' timeout: ''
}, },
timesetTimes: [], timesetTimes: [],
timesetIsCompatible: false, timesetIsCompatible: true,
timesetExists: true, timesetExists: true,
timesetHasReverse: false, timesetHasReverse: false,
timesetHasDuplicate: false timesetHasDuplicate: false,
timesetId: null
}, },
getters: { getters: {
hasFaxCapability(state, getters, rootState, rootGetters) { hasFaxCapability(state, getters, rootState, rootGetters) {
@ -79,15 +85,13 @@ export default {
return state.destinationsetId; return state.destinationsetId;
}, },
getTimesetId(state) { getTimesetId(state) {
let timeset; return state.timesetId;
for (let group in state.destinations) { },
if (!timeset) { getTimesetTimes(state) {
timeset = _.find(state.destinations[group], (o) => { return state.timesetTimes;
return o.timesetId > 0; },
}); getTimesetTimesLength(state) {
}; return state.timesetTimes.length;
};
return timeset ? timeset.timesetId : null;
} }
}, },
mutations: { mutations: {
@ -177,20 +181,28 @@ export default {
state.removeDestinationState = DestinationState.failed; state.removeDestinationState = DestinationState.failed;
state.removeDestinationError = error; state.removeDestinationError = error;
}, },
loadTimesetTimes(state, result) { removeTimeRequesting(state) {
state.timesetTimes = result; state.removeTimeState = DestinationState.requesting;
state.removeTimeError = null;
}, },
setTimesetIsCompatible(state, value) { removeTimeSucceeded(state) {
state.timesetIsCompatible = value; state.removeTimeState = DestinationState.succeeded;
state.removeTimeError = null;
}, },
setTimesetExists(state, value) { removeTimeFailed(state, error) {
state.timesetExists = value; state.removeTimeState = DestinationState.failed;
state.removeTimeError = error;
}, },
setTimesetHasReverse(state, value) { setLastRemovedDay(state, value) {
state.timesetHasReverse = value; state.lastRemovedDay = value;
}, },
setTimesetHasDuplicate(state, value) { loadTimesSucceeded(state, result) {
state.timesetHasDuplicate = value; state.timesetTimes = result.times;
state.timesetIsCompatible = result.timesetIsCompatible;
state.timesetExists = result.timesetExists;
state.timesetHasReverse = result.timesetHasReverse;
state.timesetHasDuplicate = result.timesetHasDuplicate;
state.timesetId = result.timesetId;
} }
}, },
actions: { actions: {
@ -412,11 +424,40 @@ export default {
timeset: options.timeset, timeset: options.timeset,
subscriberId: context.getters.getSubscriberId subscriberId: context.getters.getSubscriberId
}).then((result) => { }).then((result) => {
context.commit('loadTimesetTimes', result.times); context.commit('loadTimesSucceeded', result);
context.commit('setTimesetIsCompatible', result.timesetIsCompatible); });
context.commit('setTimesetExists', result.timesetExists); },
context.commit('setTimesetHasReverse', result.timesetHasReverse); deleteTimeFromTimeset(context, options) {
context.commit('setTimesetHasDuplicate', result.timesetHasDuplicate); context.commit('removeTimeRequesting');
let clonedTimes = _.cloneDeep(context.getters.getTimesetTimes);
let indexInt = parseInt(options.index);
clonedTimes.splice(indexInt, 1);
clonedTimes.forEach((time) => {
delete time.weekday;
delete time.from;
delete time.to;
});
return new Promise((resolve, reject) => {
deleteTimeFromTimeset({
subscriberId: context.getters.getSubscriberId,
timesetId: context.getters.getTimesetId,
times: clonedTimes
}).then(() => {
context.commit('setLastRemovedDay', options.removedDay);
context.commit('removeTimeSucceeded');
}).catch((err) => {
context.commit('removeTimeFailed', err.message);
});
});
},
deleteTimesetById(context, options) {
context.commit('removeTimeRequesting');
return new Promise((resolve, reject) => {
deleteTimesetById(context.getters.getTimesetId).then(() => {
context.commit('removeTimeSucceeded');
}).catch((err) => {
context.commit('removeTimeFailed', err.message);
});
}); });
} }
} }

@ -9,16 +9,17 @@ import { getMappings, getSourcesets, getTimesets,
addDestinationToDestinationset, addDestinationToDestinationset,
convertTimesetToWeekdays, convertTimesetToWeekdays,
getHoursFromRange, getHoursFromRange,
getDaysFromRange } from '../../src/api/call-forward'; getDaysFromRange,
deleteTimeFromTimeset } from '../../src/api/call-forward';
import { assert } from 'chai'; import { assert } from 'chai';
Vue.use(VueResource); Vue.use(VueResource);
describe('CallForward', function(){ describe('CallForward', function() {
const subscriberId = 123; const subscriberId = 123;
it('should get all call forward mappings', function(done){ it('should get all call forward mappings', function(done) {
let data = { let data = {
"cfb": [{ "cfb": [{
@ -52,20 +53,20 @@ describe('CallForward', function(){
}; };
Vue.http.interceptors = []; Vue.http.interceptors = [];
Vue.http.interceptors.unshift((request, next)=>{ Vue.http.interceptors.unshift((request, next) => {
next(request.respondWith(JSON.stringify(data), { next(request.respondWith(JSON.stringify(data), {
status: 200 status: 200
})); }));
}); });
getMappings(subscriberId).then((result)=>{ getMappings(subscriberId).then((result) => {
assert.deepEqual(result, data); assert.deepEqual(result, data);
done(); done();
}).catch((err)=>{ }).catch((err) => {
done(err); done(err);
}); });
}); });
it('should get all call forward sourcesets', function(done){ it('should get all call forward sourcesets', function(done) {
let innerData = [{ let innerData = [{
"_links": { "_links": {
@ -103,20 +104,20 @@ describe('CallForward', function(){
}; };
Vue.http.interceptors = []; Vue.http.interceptors = [];
Vue.http.interceptors.unshift((request, next)=>{ Vue.http.interceptors.unshift((request, next) => {
next(request.respondWith(JSON.stringify(data), { next(request.respondWith(JSON.stringify(data), {
status: 200 status: 200
})); }));
}); });
getSourcesets(subscriberId).then((result)=>{ getSourcesets(subscriberId).then((result) => {
assert.deepEqual(result, innerData); assert.deepEqual(result, innerData);
done(); done();
}).catch((err)=>{ }).catch((err) => {
done(err); done(err);
}); });
}); });
it('should get all call forward timesets', function(done){ it('should get all call forward timesets', function(done) {
let innerData = [{ let innerData = [{
"_links": { "_links": {
@ -164,20 +165,20 @@ describe('CallForward', function(){
}; };
Vue.http.interceptors = []; Vue.http.interceptors = [];
Vue.http.interceptors.unshift((request, next)=>{ Vue.http.interceptors.unshift((request, next) => {
next(request.respondWith(JSON.stringify(data), { next(request.respondWith(JSON.stringify(data), {
status: 200 status: 200
})); }));
}); });
getTimesets(subscriberId).then((result)=>{ getTimesets(subscriberId).then((result) => {
assert.deepEqual(result, innerData); assert.deepEqual(result, innerData);
done(); done();
}).catch((err)=>{ }).catch((err) => {
done(err); done(err);
}); });
}); });
it('should get all call forward destinationsets', function(done){ it('should get all call forward destinationsets', function(done) {
let innerData = [{ let innerData = [{
"_links": { "_links": {
@ -221,20 +222,20 @@ describe('CallForward', function(){
}; };
Vue.http.interceptors = []; Vue.http.interceptors = [];
Vue.http.interceptors.unshift((request, next)=>{ Vue.http.interceptors.unshift((request, next) => {
next(request.respondWith(JSON.stringify(data), { next(request.respondWith(JSON.stringify(data), {
status: 200 status: 200
})); }));
}); });
getDestinationsets(subscriberId).then((result)=>{ getDestinationsets(subscriberId).then((result) => {
assert.deepEqual(result, innerData); assert.deepEqual(result, innerData);
done(); done();
}).catch((err)=>{ }).catch((err) => {
done(err); done(err);
}); });
}); });
it('should get all call forward destinationset by id', function(done){ it('should get all call forward destinationset by id', function(done) {
let data = { let data = {
"_links": { "_links": {
@ -322,20 +323,20 @@ describe('CallForward', function(){
}; };
Vue.http.interceptors = []; Vue.http.interceptors = [];
Vue.http.interceptors.unshift((request, next)=>{ Vue.http.interceptors.unshift((request, next) => {
next(request.respondWith(JSON.stringify(data), { next(request.respondWith(JSON.stringify(data), {
status: 200 status: 200
})); }));
}); });
getDestinationsetById('3').then((result)=>{ getDestinationsetById('3').then((result) => {
assert.deepEqual(result, responseData); assert.deepEqual(result, responseData);
done(); done();
}).catch((err)=>{ }).catch((err) => {
done(err); done(err);
}); });
}); });
it('should delete destination from call forward destinationset', function(done){ it('should delete destination from call forward destinationset', function(done) {
let options = { let options = {
id: 3, id: 3,
@ -355,15 +356,15 @@ describe('CallForward', function(){
status: 204 status: 204
})); }));
}); });
deleteDestinationFromDestinationset(options).then((result)=>{ deleteDestinationFromDestinationset(options).then((result) => {
assert.isOk(result); assert.isOk(result);
done(); done();
}).catch((err)=>{ }).catch((err) => {
done(err); done(err);
}); });
}); });
it('should add destination to call forward destinationset', function(done){ it('should add destination to call forward destinationset', function(done) {
let options = { let options = {
id: 3, id: 3,
@ -375,16 +376,43 @@ describe('CallForward', function(){
} }
}; };
Vue.http.interceptors = [];
Vue.http.interceptors.unshift((request, next) => {
next(request.respondWith(JSON.stringify({}), {
status: 204
}));
});
addDestinationToDestinationset(options).then((result) => {
assert.isOk(result);
done();
}).catch((err) => {
done(err);
});
});
it('should delete time entry from call forward timeset', function(done) {
let options = {
timesetId: 3,
times: {
"weekday": "1",
"wday": "Monday",
"hour": "8-16",
"from": "8",
"to": "16"
}
};
Vue.http.interceptors = []; Vue.http.interceptors = [];
Vue.http.interceptors.unshift((request, next)=>{ Vue.http.interceptors.unshift((request, next)=>{
next(request.respondWith(JSON.stringify({}), { next(request.respondWith(JSON.stringify({}), {
status: 204 status: 204
})); }));
}); });
addDestinationToDestinationset(options).then((result)=>{ deleteTimeFromTimeset(options).then((result) => {
assert.isOk(result); assert.isOk(result);
done(); done();
}).catch((err)=>{ }).catch((err) => {
done(err); done(err);
}); });
}); });
@ -414,7 +442,7 @@ describe('CallForward', function(){
hour: "6-8", hour: "6-8",
minute: null, minute: null,
to: "9:00", to: "9:00",
wday: "1-2", wday: "1",
weekday: "Sunday" weekday: "Sunday"
}, },
{ {
@ -422,14 +450,15 @@ describe('CallForward', function(){
hour: "6-8", hour: "6-8",
minute: null, minute: null,
to: "9:00", to: "9:00",
wday: "1-2", wday: "2",
weekday: "Monday" weekday: "Monday"
} }
], ],
timesetIsCompatible: true,
timesetExists: true, timesetExists: true,
timesetHasDuplicate: false,
timesetHasReverse: false, timesetHasReverse: false,
timesetIsCompatible: true timesetHasDuplicate: false,
timesetId: 1
}; };
assert.deepEqual(convertTimesetToWeekdays(options), convertedData); assert.deepEqual(convertTimesetToWeekdays(options), convertedData);
@ -458,57 +487,58 @@ describe('CallForward', function(){
times: [ times: [
{ {
from: "6:0", from: "6:0",
hour: "6-8", hour: "6",
minute: "0-30", minute: "0-30",
to: "6:31", to: "6:31",
wday: "1-2", wday: "1",
weekday: "Sunday" weekday: "Sunday"
}, },
{ {
from: "7:0", from: "7:0",
hour: "6-8", hour: "7",
minute: "0-30", minute: "0-30",
to: "7:31", to: "7:31",
wday: "1-2", wday: "1",
weekday: "Sunday" weekday: "Sunday"
}, },
{ {
from: "8:0", from: "8:0",
hour: "6-8", hour: "8",
minute: "0-30", minute: "0-30",
to: "8:31", to: "8:31",
wday: "1-2", wday: "1",
weekday: "Sunday" weekday: "Sunday"
}, },
{ {
from: "6:0", from: "6:0",
hour: "6-8", hour: "6",
minute: "0-30", minute: "0-30",
to: "6:31", to: "6:31",
wday: "1-2", wday: "2",
weekday: "Monday" weekday: "Monday"
}, },
{ {
from: "7:0", from: "7:0",
hour: "6-8", hour: "7",
minute: "0-30", minute: "0-30",
to: "7:31", to: "7:31",
wday: "1-2", wday: "2",
weekday: "Monday" weekday: "Monday"
}, },
{ {
from: "8:0", from: "8:0",
hour: "6-8", hour: "8",
minute: "0-30", minute: "0-30",
to: "8:31", to: "8:31",
wday: "1-2", wday: "2",
weekday: "Monday" weekday: "Monday"
} }
], ],
timesetIsCompatible: true,
timesetExists: true, timesetExists: true,
timesetHasDuplicate: false,
timesetHasReverse: false, timesetHasReverse: false,
timesetIsCompatible: true timesetHasDuplicate: false,
timesetId: 1
}; };
assert.deepEqual(convertTimesetToWeekdays(options), convertedData); assert.deepEqual(convertTimesetToWeekdays(options), convertedData);
@ -547,7 +577,8 @@ describe('CallForward', function(){
timesetExists: true, timesetExists: true,
timesetHasDuplicate: false, timesetHasDuplicate: false,
timesetHasReverse: false, timesetHasReverse: false,
timesetIsCompatible: true timesetIsCompatible: true,
timesetId: 1
}; };
assert.deepEqual(convertTimesetToWeekdays(options), convertedData); assert.deepEqual(convertTimesetToWeekdays(options), convertedData);

@ -44,13 +44,20 @@ describe('CallForward', function(){
let state = { let state = {
timesetTimes: [] timesetTimes: []
}; };
let data = [ let result = {
{ weekday: "Monday", from: "8", to: "16" }, times: [
{ weekday: "Tuesday", from: "8", to: "16" }, { weekday: "Monday", from: "8", to: "16" },
{ weekday: "Wednesday", from: "8", to: "16" } { weekday: "Tuesday", from: "8", to: "16" },
] { weekday: "Wednesday", from: "8", to: "16" }
CallForwardModule.mutations.loadTimesetTimes(state, data); ],
assert.equal(state.timesetTimes, data); timesetIsCompatible: null,
timesetExists: null,
timesetHasReverse: null,
timesetHasDuplicate: null,
timesetId: null
}
CallForwardModule.mutations.loadTimesSucceeded(state, result);
assert.equal(state.timesetTimes, result.times);
}); });
}); });

Loading…
Cancel
Save