File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -51,3 +51,44 @@ test('add endpoint', async t => {
5151 await conf . setPagerDutyEndpoint ( args ) ;
5252 t . is ( conf . getConfig ( ) . custom . snsTopic ?. critical ?. endpoints ?. length , 1 ) ;
5353} ) ;
54+
55+ test ( 'Combine earlier endpoints' , async t => {
56+ const args = {
57+ config : 'test' ,
58+ service : [ 'lambda' ] ,
59+ stage : 'dev' ,
60+ endpoints : [ 'https://events.pagerduty.com/integration/abcb/enqueue' ] ,
61+ include : [ ] ,
62+ exclude : [ ] ,
63+ dry : true ,
64+ verbose : false ,
65+ } ;
66+ const conf = new config . ConfigGenerator ( args ) ;
67+ await conf . setPagerDutyEndpoint ( args ) ;
68+
69+ // Add second endpoint
70+ args . endpoints = [ 'https://events.pagerduty.com/integration/abcb/enqueue2' ] ;
71+ await conf . setPagerDutyEndpoint ( args ) ;
72+
73+ t . is ( conf . getConfig ( ) . custom . snsTopic ?. critical ?. endpoints ?. length , 2 ) ;
74+ } ) ;
75+
76+ test ( 'Combine earlier endpoints should filter out same endpoints' , async t => {
77+ const args = {
78+ config : 'test' ,
79+ service : [ 'lambda' ] ,
80+ stage : 'dev' ,
81+ endpoints : [ 'https://events.pagerduty.com/integration/abcb/enqueue' ] ,
82+ include : [ ] ,
83+ exclude : [ ] ,
84+ dry : true ,
85+ verbose : false ,
86+ } ;
87+ const conf = new config . ConfigGenerator ( args ) ;
88+ await conf . setPagerDutyEndpoint ( args ) ;
89+
90+ // Add same endpoints again
91+ await conf . setPagerDutyEndpoint ( args ) ;
92+
93+ t . is ( conf . getConfig ( ) . custom . snsTopic ?. critical ?. endpoints ?. length , 1 ) ;
94+ } ) ;
Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ export class ConfigGenerator {
9090 ) ;
9191 const newTopic = {
9292 ...topic ,
93- endpoints : endpoints . filter ( e => e ) as string [ ] ,
93+ endpoints : [ ... new Set ( [ ... ( topic . endpoints || [ ] ) , ... endpoints ] . filter ( e => e ) ) ] as string [ ] ,
9494 } ;
9595 return [ topicKey , newTopic ] ;
9696 } ) ,
You can’t perform that action at this time.
0 commit comments