@@ -82,15 +82,32 @@ describe('OpenWhiskCompileCloudant', () => {
82
82
. to . throw ( Error , 'Cloudant event property (db) missing on function: testing' ) ;
83
83
} )
84
84
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' }
87
87
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` ) ;
94
111
} )
95
112
96
113
it ( 'should return trigger for cloudant provider using package.' , ( ) => {
@@ -107,7 +124,7 @@ describe('OpenWhiskCompileCloudant', () => {
107
124
} )
108
125
} )
109
126
110
- it ( 'should return trigger for cloudant provider with manual configuration.' , ( ) => {
127
+ it ( 'should return trigger for cloudant provider with manual username & password configuration.' , ( ) => {
111
128
const config = { db : 'dbname' , username : 'user' , password : 'password' , host : 'hostname' }
112
129
const trigger = openwhiskCompileCloudant . compileCloudantTrigger ( 'testing' , config )
113
130
expect ( trigger ) . to . be . deep . equal ( {
@@ -124,6 +141,22 @@ describe('OpenWhiskCompileCloudant', () => {
124
141
} )
125
142
} )
126
143
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
+
127
160
it ( 'should return trigger with optional configuration parameters.' , ( ) => {
128
161
const config = { db : 'dbname' , username : 'user' , password : 'password' , host : 'hostname' , max : 10000 , query : { key : 'value' } , filter : 'some/view' }
129
162
const trigger = openwhiskCompileCloudant . compileCloudantTrigger ( 'testing' , config )
0 commit comments