diff --git a/models/bxml/verbs/Refer.ts b/models/bxml/verbs/Refer.ts new file mode 100644 index 0000000..d2430bd --- /dev/null +++ b/models/bxml/verbs/Refer.ts @@ -0,0 +1,35 @@ +import { NestableVerb } from '../NestableVerb'; +import { SipUri } from './SipUri'; + +export interface ReferAttributes { + referCompleteUrl?: string; + referCompleteMethod?: string; + tag?: string; +} + +/** + * @export + * @class Refer + * @extends {NestableVerb} + * Represents a Refer verb. + */ +export class Refer extends NestableVerb { + attributes: ReferAttributes; + + /** + * Creates an instance of Refer + * @param {ReferAttributes} attributes The attributes to add to the element + * @param {SipUri} sipUri The SipUri to refer to + */ + constructor(attributes?: ReferAttributes, sipUri?: SipUri) { + super('Refer', undefined, attributes, sipUri); + } + + /** + * Set the SipUri for this Refer verb + * @param {SipUri} sipUri The SipUri to refer to + */ + setSipUri(sipUri: SipUri): void { + this.nestedVerbs = [sipUri]; + } +} diff --git a/models/bxml/verbs/index.ts b/models/bxml/verbs/index.ts index 4dd67a4..ceda920 100644 --- a/models/bxml/verbs/index.ts +++ b/models/bxml/verbs/index.ts @@ -12,6 +12,7 @@ export * from './PhoneNumber'; export * from './PlayAudio'; export * from './Record'; export * from './Redirect'; +export * from './Refer'; export * from './ResumeRecording'; export * from './Ring'; export * from './SendDtmf'; diff --git a/tests/unit/models/bxml/verbs/Refer.test.ts b/tests/unit/models/bxml/verbs/Refer.test.ts new file mode 100644 index 0000000..1b86a60 --- /dev/null +++ b/tests/unit/models/bxml/verbs/Refer.test.ts @@ -0,0 +1,40 @@ +import { Verb } from '../../../../../models/bxml/Verb'; +import { SipUri } from '../../../../../models/bxml/verbs/SipUri'; +import { Refer, ReferAttributes } from '../../../../../models/bxml/verbs/Refer'; + +describe('Refer', () => { + const attributes: ReferAttributes = { + referCompleteUrl: 'https://initial.com', + referCompleteMethod: 'POST', + tag: 'initialTag' + }; + + const sipUri = new SipUri('sip:alice@atlanta.example.com'); + const newSipUri = new SipUri('sip:bob@biloxi.example.com'); + + test('should create a Refer Verb', () => { + const refer = new Refer(attributes); + const expected = ''; + + expect(refer).toBeInstanceOf(Refer); + expect(refer).toBeInstanceOf(Verb); + expect(refer.toBxml()).toBe(expected); + }); + + test('should create a Refer Verb with a nested SipUri', () => { + const refer = new Refer(attributes, sipUri); + const expected = 'sip:alice@atlanta.example.com'; + + expect(refer).toBeInstanceOf(Refer); + expect(refer).toBeInstanceOf(Verb); + expect(refer.toBxml()).toBe(expected); + }); + + test('should test the setSipUri method', () => { + const refer = new Refer(attributes, sipUri); + const expected = 'sip:bob@biloxi.example.com'; + + refer.setSipUri(newSipUri); + expect(refer.toBxml()).toBe(expected); + }); +});