Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
38 changes: 38 additions & 0 deletions models/bxml/verbs/Refer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { NestableVerb } from '../NestableVerb';
import { SipUri } from './SipUri';
Comment thread
s-aher marked this conversation as resolved.
Outdated

export interface ReferAttributes {
referCompleteUrl?: string;
referCompleteMethod?: string;
tag?: string;
}

/**
* @export
* @class Refer
* @extends {NestableVerb}
* Represents a Refer BXML verb.
* NOTE: On success the call is terminated — the remote SIP endpoint redirects away from Bandwidth.
* Recovery BXML in referCompleteUrl only makes sense for failure handling.
*/
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 child element (required for a valid Refer)
*/
constructor(attributes?: ReferAttributes, sipUri?: SipUri) {
Comment thread
s-aher marked this conversation as resolved.
Outdated
super('Refer', undefined, attributes, sipUri ? [sipUri] : undefined);
}

/**
* 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
43 changes: 43 additions & 0 deletions tests/unit/models/bxml/verbs/Refer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Refer, ReferAttributes } from '../../../../../models/bxml/verbs/Refer';
import { SipUri } from '../../../../../models/bxml/verbs/SipUri';

describe('Refer', () => {
test('should generate Refer XML with SipUri and all attributes', () => {
const attributes: ReferAttributes = {
referCompleteUrl: 'https://example.com/handleRefer',
referCompleteMethod: 'POST',
tag: 'my-tag',
};
const sipUri = new SipUri('sip:alice@atlanta.example.com');
const refer = new Refer(attributes, sipUri);

const xml = refer.toBxml();
expect(xml).toContain('<Refer');
expect(xml).toContain('referCompleteUrl="https://example.com/handleRefer"');
expect(xml).toContain('referCompleteMethod="POST"');
expect(xml).toContain('tag="my-tag"');
expect(xml).toContain('<SipUri>sip:alice@atlanta.example.com</SipUri>');
expect(xml).toContain('</Refer>');
});

test('should generate Refer XML with no attributes', () => {
const sipUri = new SipUri('sip:bob@biloxi.example.com');
const refer = new Refer(undefined, sipUri);

const xml = refer.toBxml();
expect(xml).toContain('<Refer>');
expect(xml).toContain('<SipUri>sip:bob@biloxi.example.com</SipUri>');
});

test('setSipUri should replace the nested SipUri', () => {
const sipUri1 = new SipUri('sip:alice@atlanta.example.com');
const sipUri2 = new SipUri('sip:bob@biloxi.example.com');
const refer = new Refer({}, sipUri1);

refer.setSipUri(sipUri2);
const xml = refer.toBxml();
expect(xml).not.toContain('alice');
expect(xml).toContain('sip:bob@biloxi.example.com');
});
});

Comment thread
s-aher marked this conversation as resolved.
Outdated