diff --git a/src/api/conversations.js b/src/api/conversations.js index 8f4ef4f8..9a544d50 100644 --- a/src/api/conversations.js +++ b/src/api/conversations.js @@ -4,7 +4,6 @@ import { saveAs } from 'file-saver' import Vue from 'vue' import { getList } from './common' - export function getConversations(options) { return new Promise((resolve, reject)=>{ let type = _.get(options, 'type', null); diff --git a/src/api/voicebox.js b/src/api/voicebox.js index f029b658..fd52a42b 100644 --- a/src/api/voicebox.js +++ b/src/api/voicebox.js @@ -1,7 +1,9 @@ import _ from 'lodash' +import Vue from 'vue'; import { get, + getList, patchReplace } from './common' @@ -28,10 +30,25 @@ export function setVoiceboxDelete(options) { } export function setVoiceboxAttach(options) { - return patchReplace({ - path: `api/voicemailsettings/${options.subscriberId}`, - fieldPath: 'attach', - value: options.value + return new Promise((resolve, reject)=>{ + Promise.resolve().then(()=>{ + if(options.value === false) { + return setVoiceboxDelete(options); + } + else { + return Promise.resolve(); + } + }).then(()=>{ + return patchReplace({ + path: `api/voicemailsettings/${options.subscriberId}`, + fieldPath: 'attach', + value: options.value + }); + }).then(()=>{ + resolve(); + }).catch((err)=>{ + reject(err); + }); }); } @@ -50,3 +67,78 @@ export function setVoiceboxEmail(options) { value: options.value }); } + +export function getVoiceboxGreetingByType(options) { + return new Promise((resolve, reject) => { + getList({ + path: 'api/voicemailgreetings/', + root: '_embedded.ngcp:voicemailgreetings', + params: { subscriber_id: options.id, type: options.type } + }).then((result) => { + resolve(result); + }).catch((err)=>{ + reject(err); + }); + }); +} + +export function deleteVoiceboxGreetingById(id) { + return new Promise((resolve, reject) => { + Vue.http.delete(`api/voicemailgreetings/${id}`).then(() => { + resolve(); + }).catch((err)=>{ + reject(err); + }); + }); +} + +export function createNewGreeting(formData, onProgress) { + return new Promise((resolve, reject) => { + Vue.http.post('api/voicemailgreetings/', formData, { + before(request) { + Vue.previousRequest = request; + }, + progress(e) { + if (e.lengthComputable) { + onProgress(Math.ceil((e.loaded / e.total ) * 100)); + } + } + }).then(() => { + resolve(); + }).catch((err)=>{ + reject(err); + }); + }); +} + +export function uploadGreeting(options) { + return new Promise((resolve, reject) => { + var formData = new FormData(); + var fields = _.clone(options.data); + delete fields.file; + var json = JSON.stringify(fields); + formData.append('json', json); + if (options.data.file) { + formData.append('greetingfile', options.data.file); + } + Promise.resolve().then(() => { + return getVoiceboxGreetingByType({ + id: options.data.subscriber_id, + type: options.data.type + }); + }).then((greetings) => { + if (_.some(greetings.items, { dir: options.data.dir })) { + deleteVoiceboxGreetingById(greetings.items[0].id); + } + return createNewGreeting(formData, options.onProgress); + }).then(() => { + resolve(); + }).catch((err) => { + reject(err); + }); + }); +} + +export function abortPreviousRequest() { + Vue.previousRequest.abort(); +} diff --git a/src/components/pages/Conversations/CscVoiceMailPlayer.vue b/src/components/CscAudioPlayer.vue similarity index 63% rename from src/components/pages/Conversations/CscVoiceMailPlayer.vue rename to src/components/CscAudioPlayer.vue index bfc28fe2..fe18020f 100644 --- a/src/components/pages/Conversations/CscVoiceMailPlayer.vue +++ b/src/components/CscAudioPlayer.vue @@ -1,6 +1,6 @@ diff --git a/src/components/form/CscUploadFile.vue b/src/components/form/CscUploadFile.vue new file mode 100644 index 00000000..2d8a80a8 --- /dev/null +++ b/src/components/form/CscUploadFile.vue @@ -0,0 +1,202 @@ + + + + + + diff --git a/src/components/pages/Conversations/CscVoiceMailItem.vue b/src/components/pages/Conversations/CscVoiceMailItem.vue index ffda1b9c..28361374 100644 --- a/src/components/pages/Conversations/CscVoiceMailItem.vue +++ b/src/components/pages/Conversations/CscVoiceMailItem.vue @@ -33,10 +33,12 @@ {{ $t('pages.conversations.seconds') }} - @@ -73,8 +75,9 @@ diff --git a/src/locales/en.json b/src/locales/en.json index a20af07c..67036832 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -17,7 +17,12 @@ "moveUp": "Move up", "moveDown": "Move down", "dismiss": "Dismiss", - "reset": "Reset" + "reset": "Reset", + "select": "Select", + "upload": "Upload", + "abort": "Abort", + "selectNew": "Select new", + "resetDefaults": "Reset to defaults" }, "toasts": { "callAvailable": "You are now able to start and receive calls", @@ -183,10 +188,10 @@ "removeDialogTitle": "Remove call forward destination", "removeDialogText": "You are about to remove the destination {destination}", "removeSuccessMessage": "Removed destination {destination}", - "removeErrorMessage": "An error occured while trying to delete the destination. Please try again.", + "removeErrorMessage": "An error occured while trying to delete the destination. Please try again", "addDestinationButton": "Add destination", "addDestinationSuccessMessage": "Added destination {destination}", - "addErrorMessage": "An error occured while trying to add the destination. Please try again.", + "addErrorMessage": "An error occured while trying to add the destination. Please try again", "addInputError": "Input a valid number or subscriber name", "timeout": "Timeout", "destination": "Destination", @@ -205,13 +210,13 @@ "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.", + "removeErrorMessage": "An error occured while trying to delete the time entry. Please try again", "removeTimesetSuccessMessage": "Removed timeset", - "resetErrorMessage": "An error occured while trying to reset the timesets. Please try again.", + "resetErrorMessage": "An error occured while trying to reset the timesets. Please try again", "resetSuccessMessage": "Reset of timesets completed", "addTimeSuccessMessage": "Created new timeset", - "addTimeErrorMessage": "An error occured while trying to create the timeset. Please try again.", - "loadDestinationErrorMessage": "An error occured while trying to load the destinations. Please try again.", + "addTimeErrorMessage": "An error occured while trying to create the timeset. Please try again", + "loadDestinationErrorMessage": "An error occured while trying to load the destinations. Please try again", "noTimeSet": "no time set", "addTimeButton": "Add Time", "timesetIncompatible": "The {timeset} timeset contains incompatible values. You can resolve this by resetting the {timeset} timeset.", @@ -238,17 +243,17 @@ "sourceset": "Sourceset", "source": "Source", "fieldMissing": "Both sourceset name and source is required. Please provide both and try again.", - "addSourcesetErrorMessage": "An error occured while trying to create the sourceset. Please try again.", + "addSourcesetErrorMessage": "An error occured while trying to create the sourceset. Please try again", "addSourceButton": "Add source", "addSourceSuccessMessage": "Added new source {source}", - "addSourceErrorMessage": "An error occured while trying to add the source. Please try again.", + "addSourceErrorMessage": "An error occured while trying to add the source. Please try again", "removeSourcesetButton": "Delete sourceset", - "removeSourcesetErrorMessage": "An error occured while trying to delete the sourceset. Please try again.", + "removeSourcesetErrorMessage": "An error occured while trying to delete the sourceset. Please try again", "removeSourcesetSuccessMessage": "Removed sourceset {sourceset}", "removeSourcesetDialogTitle": "Remove call forward sourceset", "removeSourcesetDialogText": "You are about to remove the sourceset {sourceset}", "removeSourceSuccessMessage": "Removed source {source}", - "removeSourceErrorMessage": "An error occured while trying to remove the source. Please try again.", + "removeSourceErrorMessage": "An error occured while trying to remove the source. Please try again", "removeSourceDialogTitle": "Remove call forward source", "removeSourceDialogText": "You are about to remove the source entry for {source}", "removeLastSourceDialogText": "Removing the last source entry is not allowed." @@ -390,48 +395,56 @@ "pageHeader": "Page Header", "content": "Content", "file": "File", - "faxFile": "Fax File", - "uploadFile": "Upload File" + "faxFile": "Fax File" }, "send": "Send", "cancel": "Cancel", - "createFaxErrorMessage": "An error occured while trying to send the fax. Please try again.", + "createFaxErrorMessage": "An error occured while trying to send the fax. Please try again", "createFaxSuccessMessage": "Sending fax completed successfully." }, "speedDial": { "whenIDial": "When I dial {slot} ...", "ring": "ring", - "loadSpeedDialErrorMessage": "An error occured while trying to load the speed dials. Please try again.", + "loadSpeedDialErrorMessage": "An error occured while trying to load the speed dials. Please try again", "noResultsMessage": "No speed dials found", "removeDialogTitle": "Remove speed dial", "removeDialogText": "You are about to remove the speed dial {slot}", - "unassignSlotErrorMessage": "An error occured while trying to unassign the speed dial slot. Please try again.", + "unassignSlotErrorMessage": "An error occured while trying to unassign the speed dial slot. Please try again", "unassignSlotSuccessMessage": "Unassigned slot {slot}", "addSpeedDial": "Add Speed Dial", "slot": "Slot", "destination": "Destination", "addNoSlotsDialogText": "All available speed dial slots have already been assigned. Please delete one first.", - "assignSlotErrorMessage": "An error occured while trying to assign the speed dial slot. Please try again.", + "assignSlotErrorMessage": "An error occured while trying to assign the speed dial slot. Please try again", "assignSlotSuccessMessage": "Assigned slot {slot}" }, "voicebox": { "label": { "changeEmail": "Change Email", "changePin": "Change PIN", - "deletionEnabled": "Voicemail will be deleted after email notification is delivered", - "deletionDisabled": "Voicemail will not be deleted after email notification is delivered", - "attachmentEnabled": "Voicemail will be attached to email notification", - "attachmentDisabled": "Voicemail will not be attached to email notification" + "deletionEnabled": "Deleted voicemail after email notification is delivered", + "deletionDisabled": "Deleted voicemail after email notification is delivered", + "attachmentEnabled": "Attach voicemail to email notification", + "attachmentDisabled": "Attach voicemail to email notification", + "busyGreeting": "Busy Greeting", + "customSoundActive": "Custom sound", + "defaultSoundActive": "Default sound" }, "pin": "PIN", - "loadSettingsErrorMessage": "An error occured while trying to load the settings. Please reload the page or check your network connection.", - "toggleDeleteSuccessMessage": "Toggled deletion successfully.", - "toggleDeleteErrorMessage": "An error occured while trying to toggle the delete option. Please try again.", - "toggleAttachSuccessMessage": "Toggled attachment successfully.", - "toggleAttachErrorMessage": "An error occured while trying to toggle the attach option. Please try again.", + "loadSettingsErrorMessage": "An error occured while trying to load the settings. Please reload the page or check your network connection", + "toggleDeleteSuccessMessage": "Toggled deletion successfully", + "toggleDeleteErrorMessage": "An error occured while trying to toggle the delete option. Please try again", + "toggleAttachSuccessMessage": "Toggled attachment successfully", + "toggleAttachErrorMessage": "An error occured while trying to toggle the attach option. Please try again", "updatePinSuccessMessage": "Changed PIN successfully.", - "updatePinErrorMessage": "An error occured while trying to update the pin field. Please try again.", - "updateEmailSuccessMessage": "Changed email successfully.", - "updateEmailErrorMessage": "An error occured while trying to update the email field. Please try again." + "updatePinErrorMessage": "An error occured while trying to update the pin field. Please try again", + "updateEmailSuccessMessage": "Changed email successfully", + "updateEmailErrorMessage": "An error occured while trying to update the email field. Please try again", + "uploadGreetingSuccessMessage": "Uploaded greeting sound successfully", + "uploadGreetingErrorMessage": "An error occured while trying to upload the greeting sound. Please try again", + "deleteGreetingSuccessMessage": "Deleted greeting sound successfully", + "deleteGreetingErrorMessage": "An error occured while trying to delete the greeting sound. Please try again", + "deleteCustomDialogTitle": "Reset busy greeting sound", + "deleteCustomDialogText": "You are about to reset the custom {type} greeting sound to defaults" } } diff --git a/src/store/voicebox.js b/src/store/voicebox.js index ebe8b6ec..c6152421 100644 --- a/src/store/voicebox.js +++ b/src/store/voicebox.js @@ -1,30 +1,29 @@ 'use strict'; -import _ from 'lodash' import { RequestState } from './common' import { getVoiceboxSettings, setVoiceboxDelete, setVoiceboxAttach, setVoiceboxPin, - setVoiceboxEmail + setVoiceboxEmail, + uploadGreeting, + abortPreviousRequest, + getVoiceboxGreetingByType, + deleteVoiceboxGreetingById } from '../api/voicebox'; import { i18n } from '../i18n'; export default { namespaced: true, state: { - voiceboxSettings: { - attach: null, - delete: null, - email: '', - id: null, - pin: null, - sms_number: '' - }, - loadingState: RequestState.initial, - loadingError: null, + voiceboxSettingDelete: false, + voiceboxSettingAttach: false, + voiceboxSettingPin: '', + voiceboxSettingEmail: '', + loadSettingsState: RequestState.initial, + loadSettingsError: null, toggleDeleteState: RequestState.initial, toggleDeleteError: null, toggleAttachState: RequestState.initial, @@ -32,47 +31,66 @@ export default { updatePinState: RequestState.initial, updatePinError: null, updateEmailState: RequestState.initial, - updateEmailError: null + updateEmailError: null, + uploadBusyGreetingState: RequestState.initial, + uploadBusyGreetingError: null, + uploadProgress: 0, + busyGreetingId: null, + unavailGreetingId: null, + loadBusyGreetingState: RequestState.initial, + loadBusyGreetingError: null, + deleteGreetingState: RequestState.initial, + deleteGreetingError: null }, getters: { subscriberId(state, getters, rootState, rootGetters) { return parseInt(rootGetters['user/getSubscriberId']); }, isSettingsLoaded(state) { - return state.loadingState === 'succeeded'; + return state.loadSettingsState === 'succeeded'; }, isDeleteRequesting(state) { - return state.toggleDeleteState === 'requesting'; + return state.loadSettingsState === 'requesting' || + state.toggleDeleteState === 'requesting'; }, isAttachRequesting(state) { - return state.toggleAttachState === 'requesting'; + return state.loadSettingsState === 'requesting' || + state.toggleAttachState === 'requesting'; }, isPinRequesting(state) { - return state.updatePinState === 'requesting'; + return state.loadSettingsState === 'requesting' || + state.updatePinState === 'requesting'; }, isEmailRequesting(state) { - return state.updateEmailState === 'requesting'; + return state.loadSettingsState === 'requesting' || + state.updateEmailState === 'requesting'; }, - loadingState(state) { - return state.loadingState; + loadSettingsState(state) { + return state.loadSettingsState; }, - loadingError(state) { - return state.loadingError || + loadSettingsError(state) { + return state.loadSettingsError || i18n.t('voicebox.loadSettingsErrorMessage'); }, voiceboxDelete(state) { - return _.get(state.voiceboxSettings, 'delete', false); + return state.voiceboxSettingDelete; }, voiceboxAttach(state) { - return _.get(state.voiceboxSettings, 'attach', false); + return state.voiceboxSettingAttach; }, - deleteLabel(state) { - return state.voiceboxSettings.delete ? + voiceboxPin(state) { + return state.voiceboxSettingPin; + }, + voiceboxEmail(state) { + return state.voiceboxSettingEmail; + }, + deleteLabel(state, getters) { + return getters.voiceboxDelete ? i18n.t('voicebox.label.deletionEnabled') : i18n.t('voicebox.label.deletionDisabled'); }, - attachLabel(state) { - return state.voiceboxSettings.attach ? + attachLabel(state, getters) { + return getters.voiceboxAttach ? i18n.t('voicebox.label.attachmentEnabled') : i18n.t('voicebox.label.attachmentDisabled'); }, @@ -106,21 +124,64 @@ export default { updateEmailError(state) { return state.updateEmailError || i18n.t('voicebox.updateEmailErrorMessage'); + }, + uploadBusyGreetingState(state) { + return state.uploadBusyGreetingState; + }, + uploadBusyGreetingError(state) { + return state.uploadBusyGreetingError || + i18n.t('voicebox.uploadGreetingErrorMessage'); + }, + uploadProgress(state) { + return state.uploadProgress; + }, + uploadBusyGreetingRequesting(state) { + return state.uploadBusyGreetingState === 'requesting'; + }, + busyGreetingId(state) { + return state.busyGreetingId; + }, + unavailGreetingId(state) { + return state.unavailGreetingId; + }, + deleteGreetingState(state) { + return state.deleteGreetingState; + }, + deleteGreetingError(state) { + return state.deleteGreetingError || + i18n.t('voicebox.deleteGreetingErrorMessage'); + }, + isBusyGreetingLoaded(state) { + return state.loadBusyGreetingState === 'succeeded'; + }, + busyGreetingLabel(state) { + return state.busyGreetingId ? i18n.t('voicebox.label.customSoundActive') : + i18n.t('voicebox.label.defaultSoundActive'); } }, mutations: { - loadingRequesting(state) { - state.loadingState = RequestState.requesting; - state.loadingError = null; - }, - loadingSucceeded(state, settings) { - state.loadingState = RequestState.succeeded; - state.voiceboxSettings = settings; - state.loadingError = null; - }, - loadingFailed(state, error) { - state.loadingState = RequestState.failed; - state.loadingError = error; + loadedSettings(state, settings) { + state.voiceboxSettingDelete = settings.delete; + state.voiceboxSettingAttach = settings.attach; + state.voiceboxSettingPin = settings.pin; + state.voiceboxSettingEmail = settings.email; + state.loadSettingsError = null; + }, + loadSettingsRequesting(state) { + state.loadSettingsState = RequestState.requesting; + state.loadSettingsError = null; + }, + loadSettingsSucceeded(state, settings) { + state.loadSettingsState = RequestState.succeeded; + state.loadSettingsError = null; + state.voiceboxSettingDelete = settings.delete; + state.voiceboxSettingAttach = settings.attach; + state.voiceboxSettingPin = settings.pin; + state.voiceboxSettingEmail = settings.email; + }, + loadSettingsFailed(state, error) { + state.loadSettingsState = RequestState.succeeded; + state.loadSettingsError = error; }, toggleDeleteRequesting(state) { state.toggleDeleteState = RequestState.requesting; @@ -169,16 +230,62 @@ export default { updateEmailFailed(state, error) { state.updateEmailState = RequestState.failed; state.updateEmailError = error; + }, + uploadBusyGreetingRequesting(state) { + state.uploadBusyGreetingState = RequestState.requesting; + state.uploadBusyGreetingError = null; + }, + uploadBusyGreetingSucceeded(state) { + state.uploadBusyGreetingState = RequestState.succeeded; + state.uploadBusyGreetingError = null; + }, + uploadBusyGreetingFailed(state, error) { + state.uploadBusyGreetingState = RequestState.failed; + state.uploadBusyGreetingError = error; + }, + uploadProgress(state, progress) { + state.uploadProgress = progress; + }, + resetProgress(state) { + state.uploadProgress = 0; + }, + loadBusyGreetingRequesting(state) { + state.busyGreetingId = null, + state.loadBusyGreetingState = RequestState.requesting; + state.loadBusyGreetingError = null; + }, + loadBusyGreetingSucceeded(state, greetings) { + if (greetings.length > 0) { + state.busyGreetingId = greetings[0].id; + } + state.loadBusyGreetingState = RequestState.succeeded; + state.loadBusyGreetingError = null; + }, + loadBusyGreetingFailed(state, error) { + state.loadBusyGreetingState = RequestState.failed; + state.loadBusyGreetingError = error; + }, + deleteGreetingRequesting(state) { + state.deleteGreetingState = RequestState.requesting; + state.deleteGreetingError = null; + }, + deleteGreetingSucceeded(state) { + state.deleteGreetingState = RequestState.succeeded; + state.deleteGreetingError = null; + }, + deleteGreetingFailed(state, error) { + state.deleteGreetingState = RequestState.failed; + state.deleteGreetingError = error; } }, actions: { getVoiceboxSettings(context) { - context.commit('loadingRequesting'); + context.commit('loadSettingsRequesting'); getVoiceboxSettings(context.getters.subscriberId).then((settings) => { - context.commit('loadingSucceeded', settings); + context.commit('loadSettingsSucceeded', settings); }).catch((err) => { - context.commit('loadingFailed', err.message); - }) + context.commit('loadSettingsFailed', err.message); + }); }, toggleDelete(context) { context.commit('toggleDeleteRequesting'); @@ -186,8 +293,10 @@ export default { subscriberId: context.getters.subscriberId, value: !context.getters.voiceboxDelete }).then(() => { + return getVoiceboxSettings(context.getters.subscriberId); + }).then((settings)=>{ + context.commit('loadedSettings', settings); context.commit('toggleDeleteSucceeded'); - context.dispatch('getVoiceboxSettings'); }).catch((err) => { context.commit('toggleDeleteFailed', err.message); context.dispatch('getVoiceboxSettings'); @@ -199,8 +308,10 @@ export default { subscriberId: context.getters.subscriberId, value: !context.getters.voiceboxAttach }).then(() => { + return getVoiceboxSettings(context.getters.subscriberId); + }).then((settings)=>{ + context.commit('loadedSettings', settings); context.commit('toggleAttachSucceeded'); - context.dispatch('getVoiceboxSettings'); }).catch((err) => { context.commit('toggleAttachFailed', err.message); context.dispatch('getVoiceboxSettings'); @@ -212,8 +323,10 @@ export default { subscriberId: context.getters.subscriberId, value: value }).then(() => { + return getVoiceboxSettings(context.getters.subscriberId); + }).then((settings)=>{ + context.commit('loadedSettings', settings); context.commit('updatePinSucceeded'); - context.dispatch('getVoiceboxSettings'); }).catch((err) => { context.commit('updatePinFailed', err.message); }); @@ -224,11 +337,58 @@ export default { subscriberId: context.getters.subscriberId, value: value }).then(() => { + return getVoiceboxSettings(context.getters.subscriberId); + }).then((settings)=>{ + context.commit('loadedSettings', settings); context.commit('updateEmailSucceeded'); - context.dispatch('getVoiceboxSettings'); }).catch((err) => { context.commit('updateEmailFailed', err.message); }); + }, + uploadGreeting(context, $options) { + let options = Object.assign($options, { + subscriber_id: context.getters.subscriberId, + type: $options.dir + }); + context.commit('uploadBusyGreetingRequesting'); + uploadGreeting({ + data: options, + onProgress: (progress) => { context.commit('uploadProgress', progress) } + }).then(() => { + context.commit('loadBusyGreetingRequesting'); + return getVoiceboxGreetingByType({ + id: context.getters.subscriberId, + type: 'busy' + }) + }).then((greetings)=>{ + context.commit('loadBusyGreetingSucceeded', greetings.items); + context.commit('uploadBusyGreetingSucceeded'); + }).catch((err) => { + context.commit('uploadBusyGreetingFailed', err.message); + }); + }, + abortPreviousRequest() { + abortPreviousRequest(); + }, + loadBusyGreeting(context) { + context.commit('loadBusyGreetingRequesting'); + getVoiceboxGreetingByType({ + id: context.getters.subscriberId, + type: 'busy' + }).then((greetings) => { + context.commit('loadBusyGreetingSucceeded', greetings.items); + }).catch((err) => { + context.commit('loadBusyGreetingFailed', err.message); + }); + }, + deleteGreeting(context, id) { + context.commit('deleteGreetingRequesting'); + deleteVoiceboxGreetingById(id).then(() => { + context.commit('deleteGreetingSucceeded'); + context.dispatch('loadBusyGreeting'); + }).catch((err) => { + context.commit('deleteGreetingFailed', err.message); + }); } } }; diff --git a/src/themes/app.common.styl b/src/themes/app.common.styl index 26070930..6acbdba8 100644 --- a/src/themes/app.common.styl +++ b/src/themes/app.common.styl @@ -1,6 +1,13 @@ @import 'quasar.variables' +.q-field + position relative + +.csc-toggle-disabled + .q-option-label + color: $faded + .q-list-highlight .csc-item-expanded:hover background-color white @@ -118,3 +125,6 @@ .q-field-icon color $primary + +.csc-black-label + color black diff --git a/t/api/voicebox.js b/t/api/voicebox.js index 811b19cf..aaa120c2 100644 --- a/t/api/voicebox.js +++ b/t/api/voicebox.js @@ -4,20 +4,22 @@ import Vue from 'vue'; import VueResource from 'vue-resource'; import { - get + get, + getList } from '../../src/api/common'; import { - getVoiceboxSettings + getVoiceboxSettings, + getVoiceboxGreetingByType } from '../../src/api/voicebox'; import { assert } from 'chai'; Vue.use(VueResource); -describe('Voicebox', function(){ +describe('Voicebox', function() { const subscriberId = 123; - it('should get subscriber\'s voicebox settings', function(done){ + it('should get subscriber\'s voicebox settings', function(done) { let data = { "_links" : { @@ -64,15 +66,50 @@ describe('Voicebox', function(){ }; Vue.http.interceptors = []; - Vue.http.interceptors.unshift((request, next)=>{ + Vue.http.interceptors.unshift((request, next) => { next(request.respondWith(JSON.stringify(data), { status: 200 })); }); - getVoiceboxSettings(subscriberId).then((result)=>{ + getVoiceboxSettings(subscriberId).then((result) => { assert.deepEqual(result, settings); done(); - }).catch((err)=>{ + }).catch((err) => { + done(err); + }); + }); + + it('should get subscriber\'s busy greeting', function(done) { + + let data = { + "_embedded" : { + "ngcp:voicemailgreetings" : [ + { + "dir" : "busy", + "id" : 1, + "subscriber_id" : 123 + } + ] + }, + "total_count" : 1 + }; + + let greeting = { + "dir" : "busy", + "id" : 1, + "subscriber_id" : 123 + }; + + Vue.http.interceptors = []; + Vue.http.interceptors.unshift((request, next) => { + next(request.respondWith(JSON.stringify(data), { + status: 200 + })); + }); + getVoiceboxGreetingByType({id: subscriberId, type: 'busy'}).then((result) => { + assert.deepEqual(result.items[0], greeting); + done(); + }).catch((err) => { done(err); }); }); diff --git a/t/store/voicebox.js b/t/store/voicebox.js index 40e36b22..4993ee8c 100644 --- a/t/store/voicebox.js +++ b/t/store/voicebox.js @@ -8,14 +8,10 @@ describe('Voicebox', function(){ it('should load all voicebox settings into store', function(){ let state = { - voiceboxSettings: { - attach: null, - delete: null, - email: '', - id: null, - pin: null, - sms_number: '' - } + voiceboxSettingDelete: false, + voiceboxSettingAttach: false, + voiceboxSettingPin: '', + voiceboxSettingEmail: '', }; let settings = { attach: true, @@ -25,8 +21,25 @@ describe('Voicebox', function(){ pin: 1234, sms_number: '' }; - VoiceboxModule.mutations.loadingSucceeded(state, settings); - assert.deepEqual(state.voiceboxSettings, settings); + VoiceboxModule.mutations.loadSettingsSucceeded(state, settings); + assert.equal(state.voiceboxSettingDelete, settings.delete); + assert.equal(state.voiceboxSettingAttach, settings.attach); + assert.equal(state.voiceboxSettingEmail, settings.email); + assert.equal(state.voiceboxSettingPin, settings.pin); + + }); + + it('should load all busy greeting id into store', function(){ + let state = { + busyGreetingId: null + }; + let greetings = [ + { + id: 1 + } + ]; + VoiceboxModule.mutations.loadBusyGreetingSucceeded(state, greetings); + assert.deepEqual(state.busyGreetingId, greetings[0].id); }); });