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
4 changes: 2 additions & 2 deletions common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ export const toPathString = function (url: URL) {
}

export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
return function <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH): Promise<R> {
const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url};
return axios.request<T, R>(axiosRequestArgs);
return axios.request<T, R>(axiosRequestArgs) as Promise<R>;
Comment on lines -111 to +113

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix for CI error unrelated to PR change. Actions aren't required so can remove this if wanted

};
}
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';

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 {SipUri} sipUri The SipUri child element (required - spec mandates exactly one)
* @param {ReferAttributes} attributes The attributes to add to the element
*/
constructor(sipUri: SipUri, attributes?: ReferAttributes) {
super('Refer', undefined, attributes, [sipUri]);
}

/**
* Set the SipUri for this Refer verb
* @param {SipUri} sipUri The SipUri to refer to
*/
setSipUri(sipUri: SipUri): void {
// Replaces the single required SipUri child - <Refer> allows exactly one.
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
42 changes: 42 additions & 0 deletions tests/unit/models/bxml/verbs/Refer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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(sipUri, attributes);

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(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');
});
});