@@ -82,15 +82,32 @@ describe('OpenWhiskCompileCloudant', () => {
8282 . to . throw ( Error , 'Cloudant event property (db) missing on function: testing' ) ;
8383 } )
8484
85- it ( 'should throw errors for missing mandatory parameters without package' , ( ) => {
86- const config = { db : 'dbname' , username : 'user' , password : 'password' , host : 'hostname' }
85+ it ( 'should throw errors for missing host parameters without package' , ( ) => {
86+ const config = { db : 'dbname' , username : 'user' , password : 'password' }
8787
88- Object . keys ( config ) . forEach ( key => {
89- const cloned = Object . assign ( { } , config )
90- cloned [ key ] = ''
91- expect ( ( ) => openwhiskCompileCloudant . compileCloudantTrigger ( 'testing' , cloned ) )
92- . to . throw ( Error , `Cloudant event property (${ key } ) missing on function: testing` ) ;
93- } )
88+ expect ( ( ) => openwhiskCompileCloudant . compileCloudantTrigger ( 'testing' , config ) )
89+ . to . throw ( Error , `Cloudant event property (host) missing on function: testing` ) ;
90+ } )
91+
92+ it ( 'should throw errors for missing username parameter without package' , ( ) => {
93+ const config = { db : 'dbname' , host : 'host.com' , password : 'password' }
94+
95+ expect ( ( ) => openwhiskCompileCloudant . compileCloudantTrigger ( 'testing' , config ) )
96+ . to . throw ( Error , `Cloudant event authentication property (username & password or iam_api_key) missing on function: testing` ) ;
97+ } )
98+
99+ it ( 'should throw errors for missing password parameter without package' , ( ) => {
100+ const config = { db : 'dbname' , host : 'host.com' , username : 'username' }
101+
102+ expect ( ( ) => openwhiskCompileCloudant . compileCloudantTrigger ( 'testing' , config ) )
103+ . to . throw ( Error , `Cloudant event authentication property (username & password or iam_api_key) missing on function: testing` ) ;
104+ } )
105+
106+ it ( 'should throw errors for missing authentication parameters without package' , ( ) => {
107+ const config = { db : 'dbname' , host : 'host.com' }
108+
109+ expect ( ( ) => openwhiskCompileCloudant . compileCloudantTrigger ( 'testing' , config ) )
110+ . to . throw ( Error , `Cloudant event authentication property (username & password or iam_api_key) missing on function: testing` ) ;
94111 } )
95112
96113 it ( 'should return trigger for cloudant provider using package.' , ( ) => {
@@ -107,7 +124,7 @@ describe('OpenWhiskCompileCloudant', () => {
107124 } )
108125 } )
109126
110- it ( 'should return trigger for cloudant provider with manual configuration.' , ( ) => {
127+ it ( 'should return trigger for cloudant provider with manual username & password configuration.' , ( ) => {
111128 const config = { db : 'dbname' , username : 'user' , password : 'password' , host : 'hostname' }
112129 const trigger = openwhiskCompileCloudant . compileCloudantTrigger ( 'testing' , config )
113130 expect ( trigger ) . to . be . deep . equal ( {
@@ -124,6 +141,22 @@ describe('OpenWhiskCompileCloudant', () => {
124141 } )
125142 } )
126143
144+ it ( 'should return trigger for cloudant provider with manual iam api key configuration.' , ( ) => {
145+ const config = { db : 'dbname' , iam_api_key : 'api_key' , host : 'hostname' }
146+ const trigger = openwhiskCompileCloudant . compileCloudantTrigger ( 'testing' , config )
147+ expect ( trigger ) . to . be . deep . equal ( {
148+ name : `${ serverless . service . service } _testing_cloudant_${ config . db } ` ,
149+ content : {
150+ feed : `/whisk.system/cloudant/changes` ,
151+ feed_parameters : {
152+ iamApiKey : config . iam_api_key ,
153+ host : config . host ,
154+ dbname : config . db
155+ }
156+ }
157+ } )
158+ } )
159+
127160 it ( 'should return trigger with optional configuration parameters.' , ( ) => {
128161 const config = { db : 'dbname' , username : 'user' , password : 'password' , host : 'hostname' , max : 10000 , query : { key : 'value' } , filter : 'some/view' }
129162 const trigger = openwhiskCompileCloudant . compileCloudantTrigger ( 'testing' , config )
0 commit comments