Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions models/bxml/verbs/Refer.ts
Original file line number Diff line number Diff line change
@@ -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];
Comment thread
s-aher marked this conversation as resolved.
}
}
1 change: 1 addition & 0 deletions models/bxml/verbs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/models/bxml/verbs/Refer.test.ts
Original file line number Diff line number Diff line change
@@ -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 = '<Refer referCompleteUrl="https://initial.com" referCompleteMethod="POST" tag="initialTag"/>';

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 = '<Refer referCompleteUrl="https://initial.com" referCompleteMethod="POST" tag="initialTag"><SipUri>sip:alice@atlanta.example.com</SipUri></Refer>';

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 = '<Refer referCompleteUrl="https://initial.com" referCompleteMethod="POST" tag="initialTag"><SipUri>sip:bob@biloxi.example.com</SipUri></Refer>';

refer.setSipUri(newSipUri);
expect(refer.toBxml()).toBe(expected);
});
});