Skip to content

Commit 785428c

Browse files
committed
VAPI-3165 fixed review comments
1 parent d3414d9 commit 785428c

4 files changed

Lines changed: 38 additions & 16 deletions

File tree

models/bxml/verbs/Refer.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NestableVerb } from '../NestableVerb';
2-
import { SipUri } from './SipUri';
2+
import { ReferSipUri } from './ReferSipUri';
33

44
export interface ReferAttributes {
55
referCompleteUrl?: string;
@@ -20,19 +20,19 @@ export class Refer extends NestableVerb {
2020

2121
/**
2222
* Creates an instance of Refer
23+
* @param {ReferSipUri} sipUri The SipUri child element (required — spec mandates exactly one)
2324
* @param {ReferAttributes} attributes The attributes to add to the element
24-
* @param {SipUri} sipUri The SipUri child element (required for a valid Refer)
2525
*/
26-
constructor(attributes?: ReferAttributes, sipUri?: SipUri) {
27-
super('Refer', undefined, attributes, sipUri ? [sipUri] : undefined);
26+
constructor(sipUri: ReferSipUri, attributes?: ReferAttributes) {
27+
super('Refer', undefined, attributes, [sipUri]);
2828
}
2929

3030
/**
3131
* Set the SipUri for this Refer verb
32-
* @param {SipUri} sipUri The SipUri to refer to
32+
* @param {ReferSipUri} sipUri The SipUri to refer to
3333
*/
34-
setSipUri(sipUri: SipUri): void {
34+
setSipUri(sipUri: ReferSipUri): void {
35+
// Replaces the single required SipUri child — <Refer> allows exactly one.
3536
this.nestedVerbs = [sipUri];
3637
}
3738
}
38-

models/bxml/verbs/ReferSipUri.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Verb } from '../Verb';
2+
3+
/**
4+
* @export
5+
* @class ReferSipUri
6+
* @extends {Verb}
7+
* Represents a SipUri child element scoped to the Refer verb.
8+
* Unlike the Transfer-scoped SipUri, this accepts only a URI — no
9+
* transferAnswerUrl, uui, username/password, or other Transfer attributes.
10+
*/
11+
export class ReferSipUri extends Verb {
12+
uri: string;
13+
14+
/**
15+
* Creates an instance of ReferSipUri
16+
* @param {string} uri The SIP URI to refer to (must start with sip:)
17+
*/
18+
constructor(uri: string) {
19+
super('SipUri', uri);
20+
}
21+
}
22+

models/bxml/verbs/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export * from './PlayAudio';
1313
export * from './Record';
1414
export * from './Redirect';
1515
export * from './Refer';
16+
export * from './ReferSipUri';
1617
export * from './ResumeRecording';
1718
export * from './Ring';
1819
export * from './SendDtmf';
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Refer, ReferAttributes } from '../../../../../models/bxml/verbs/Refer';
2-
import { SipUri } from '../../../../../models/bxml/verbs/SipUri';
2+
import { ReferSipUri } from '../../../../../models/bxml/verbs/ReferSipUri';
33

44
describe('Refer', () => {
55
test('should generate Refer XML with SipUri and all attributes', () => {
@@ -8,8 +8,8 @@ describe('Refer', () => {
88
referCompleteMethod: 'POST',
99
tag: 'my-tag',
1010
};
11-
const sipUri = new SipUri('sip:alice@atlanta.example.com');
12-
const refer = new Refer(attributes, sipUri);
11+
const sipUri = new ReferSipUri('sip:alice@atlanta.example.com');
12+
const refer = new Refer(sipUri, attributes);
1313

1414
const xml = refer.toBxml();
1515
expect(xml).toContain('<Refer');
@@ -21,23 +21,22 @@ describe('Refer', () => {
2121
});
2222

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

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

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

3737
refer.setSipUri(sipUri2);
3838
const xml = refer.toBxml();
3939
expect(xml).not.toContain('alice');
4040
expect(xml).toContain('sip:bob@biloxi.example.com');
4141
});
4242
});
43-

0 commit comments

Comments
 (0)