@@ -31,6 +31,7 @@ var forEach = require('lodash.foreach');
3131var assign = require ( 'lodash.assign' ) ;
3232var pick = require ( 'lodash.pick' ) ;
3333var omitBy = require ( 'lodash.omitby' ) ;
34+ var request = require ( 'request' ) ;
3435var util = require ( 'util' ) ;
3536var path = require ( 'path' ) ;
3637
@@ -362,6 +363,41 @@ describe('Expected Behavior', function() {
362363 } ) ;
363364} ) ;
364365
366+ describe ( 'Error Reporting API' , function ( ) {
367+ [
368+ {
369+ name : 'when a valid API key is given' ,
370+ getKey : ( ) => env . apiKey ,
371+ message : 'Message cannot be empty.'
372+ } ,
373+ {
374+ name : 'when an empty API key is given' ,
375+ getKey : ( ) => '' ,
376+ message : 'The request is missing a valid API key.'
377+ } ,
378+ {
379+ name : 'when an invalid API key is given' ,
380+ getKey : ( ) => env . apiKey . slice ( 1 ) + env . apiKey [ 0 ] ,
381+ message : 'API key not valid. Please pass a valid API key.'
382+ }
383+ ] . forEach ( function ( testCase ) {
384+ it ( `should return an expected message ${ testCase . name } ` , function ( done ) {
385+ this . timeout ( 30000 ) ;
386+ const API = 'https://clouderrorreporting.googleapis.com/v1beta1' ;
387+ const key = testCase . getKey ( ) ;
388+ request . post ( {
389+ url : `${ API } /projects/${ env . projectId } /events:report?key=${ key } ` ,
390+ json : { } ,
391+ } , ( err , response , body ) => {
392+ assert . ok ( ! err && body . error ) ;
393+ assert . strictEqual ( response . statusCode , 400 ) ;
394+ assert . strictEqual ( body . error . message , testCase . message ) ;
395+ done ( ) ;
396+ } ) ;
397+ } ) ;
398+ } ) ;
399+ } ) ;
400+
365401describe ( 'error-reporting' , function ( ) {
366402 const SRC_ROOT = path . join ( __dirname , '..' , 'src' ) ;
367403 const TIMESTAMP = Date . now ( ) ;
0 commit comments