@@ -12,10 +12,14 @@ export default function(express) {
1212 'Content-Type' : HEADERS . JSON
1313 } ] ,
1414 endpoint : "http://localhost:55550/api/notify" ,
15- content : '{"color":"green","message":"New package published: * {{ name }}*","notify":true,"message_format":"text"}'
15+ content : '{"color":"green","message":"New package published: * {{ name }}*. Publisher name: * {{ publisher.name }} *. ","notify":true,"message_format":"text"}'
1616 }
1717 } ;
1818
19+ const publisherInfo = {
20+ name : "publisher-name-test"
21+ } ;
22+
1923 describe ( 'notifications' , ( ) => {
2024
2125 beforeAll ( function ( ) {
@@ -33,10 +37,14 @@ export default function(express) {
3337 name : "pkg-test"
3438 } ;
3539
36- notify ( metadata , config ) . then ( function ( body ) {
40+ notify ( metadata , config , publisherInfo ) . then ( function ( body ) {
3741 const jsonBody = JSON . parse ( body ) ;
38- assert . ok ( `New package published: * ${ metadata . name } *` === jsonBody . message ,
39- 'Body notify message should be equal' ) ;
42+ assert . ok (
43+ `New package published: * ${ metadata . name } *. Publisher name: * ${
44+ publisherInfo . name
45+ } *.` === jsonBody . message ,
46+ "Body notify message should be equal"
47+ ) ;
4048 done ( ) ;
4149 } , function ( err ) {
4250 assert . fail ( err ) ;
@@ -54,10 +62,14 @@ export default function(express) {
5462 'Content-Type' : HEADERS . JSON
5563 } ;
5664
57- notify ( metadata , configMultipleHeader ) . then ( function ( body ) {
65+ notify ( metadata , configMultipleHeader , publisherInfo ) . then ( function ( body ) {
5866 const jsonBody = JSON . parse ( body ) ;
59- assert . ok ( `New package published: * ${ metadata . name } *` === jsonBody . message ,
60- 'Body notify message should be equal' ) ;
67+ assert . ok (
68+ `New package published: * ${ metadata . name } *. Publisher name: * ${
69+ publisherInfo . name
70+ } *.` === jsonBody . message ,
71+ "Body notify message should be equal"
72+ ) ;
6173 done ( ) ;
6274 } , function ( err ) {
6375 assert . fail ( err ) ;
@@ -85,11 +97,15 @@ export default function(express) {
8597 multipleNotificationsEndpoint . notify . push ( notificationSettings ) ;
8698 }
8799
88- notify ( metadata , multipleNotificationsEndpoint ) . then ( function ( body ) {
100+ notify ( metadata , multipleNotificationsEndpoint , publisherInfo ) . then ( function ( body ) {
89101 body . forEach ( function ( notification ) {
90102 const jsonBody = JSON . parse ( notification ) ;
91- assert . ok ( `New package published: * ${ metadata . name } *` === jsonBody . message ,
92- 'Body notify message should be equal' ) ;
103+ assert . ok (
104+ `New package published: * ${ metadata . name } *. Publisher name: * ${
105+ publisherInfo . name
106+ } *.` === jsonBody . message ,
107+ "Body notify message should be equal"
108+ ) ;
93109 } ) ;
94110 done ( ) ;
95111 } , function ( err ) {
@@ -105,7 +121,7 @@ export default function(express) {
105121 const configFail = _ . cloneDeep ( config ) ;
106122 configFail . notify . endpoint = "http://localhost:55550/api/notify/bad" ;
107123
108- notify ( metadata , configFail ) . then ( function ( ) {
124+ notify ( metadata , configFail , publisherInfo ) . then ( function ( ) {
109125 assert . equal ( false , 'This service should fails with status code 400' ) ;
110126 done ( ) ;
111127 } , function ( err ) {
@@ -114,5 +130,31 @@ export default function(express) {
114130 } ) ;
115131 } ) ;
116132
133+ test ( "publisher property should not be overridden if it exists in metadata" , done => {
134+ const metadata = {
135+ name : "pkg-test" ,
136+ publisher : {
137+ name : "existing-publisher-name"
138+ }
139+ } ;
140+
141+ notify ( metadata , config , publisherInfo ) . then (
142+ function ( body ) {
143+ const jsonBody = JSON . parse ( body ) ;
144+ assert . ok (
145+ `New package published: * ${ metadata . name } *. Publisher name: * ${
146+ metadata . publisher . name
147+ } *.` === jsonBody . message ,
148+ "Body notify message should be equal"
149+ ) ;
150+ done ( ) ;
151+ } ,
152+ function ( err ) {
153+ assert . fail ( err ) ;
154+ done ( ) ;
155+ }
156+ ) ;
157+ } ) ;
158+
117159 } ) ;
118160}
0 commit comments