@@ -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,52 @@ describe('Expected Behavior', function() {
362363 } ) ;
363364} ) ;
364365
366+ describe ( 'Error Reporting API' , function ( ) {
367+ const API = 'https://clouderrorreporting.googleapis.com/v1beta1' ;
368+
369+ function getMessageForApiKey ( key , cb ) {
370+ request . post ( {
371+ url : `${ API } /projects/${ env . projectId } /events:report?key=${ key } ` ,
372+ json : { } ,
373+ } , ( err , response , body ) => {
374+ assert . ok ( ! err && body . error ) ;
375+ cb ( body . error . message ) ;
376+ } ) ;
377+ }
378+
379+ [
380+ {
381+ name : 'when a valid API key is given' ,
382+ getKey : ( ) => env . apiKey ,
383+ message : 'Message cannot be empty.'
384+ } ,
385+ {
386+ name : 'when an empty API key is given' ,
387+ getKey : ( ) => '' ,
388+ message : 'The request is missing a valid API key.'
389+ } ,
390+ {
391+ name : 'when an invalid API key is given' ,
392+ getKey : ( ) => env . apiKey . slice ( 1 ) + env . apiKey [ 0 ] ,
393+ message : 'API key not valid. Please pass a valid API key.'
394+ }
395+ ] . forEach ( function ( testCase ) {
396+ it ( `should return an expected message ${ testCase . name } ` , function ( done ) {
397+ this . timeout ( 30000 ) ;
398+ const key = testCase . getKey ( ) ;
399+ request . post ( {
400+ url : `${ API } /projects/${ env . projectId } /events:report?key=${ key } ` ,
401+ json : { } ,
402+ } , ( err , response , body ) => {
403+ assert . ok ( ! err && body . error ) ;
404+ assert . strictEqual ( response . statusCode , 400 ) ;
405+ assert . strictEqual ( body . error . message , testCase . message ) ;
406+ done ( ) ;
407+ } ) ;
408+ } ) ;
409+ } ) ;
410+ } ) ;
411+
365412describe ( 'error-reporting' , function ( ) {
366413 const SRC_ROOT = path . join ( __dirname , '..' , 'src' ) ;
367414 const TIMESTAMP = Date . now ( ) ;
0 commit comments