@@ -432,7 +432,7 @@ describe("AssociationsService", () => {
432432
433433 describe ( "createAssociation" , ( ) => {
434434 let associationsService : AssociationsService ;
435- const inviteeEmailAddress = "[email protected] " ; 435+ const userId = "1234567890 " ;
436436
437437 beforeEach ( ( ) => {
438438 sinon . reset ( ) ;
@@ -442,17 +442,7 @@ describe("AssociationsService", () => {
442442
443443 it ( "should return 201 response if a new association created" , async ( ) => {
444444 sinon . stub ( requestClient , "httpPost" ) . resolves ( mockPostResponse [ 201 ] ) ;
445- await associationsService . createAssociation ( companyNumber ) . then ( ( data ) => {
446- expect ( data . httpStatusCode ) . to . equal ( 201 ) ;
447- const castedData : Resource < NewAssociationResponse > = data as Resource < NewAssociationResponse > ;
448- expect ( castedData ) . to . exist ;
449- expect ( castedData . resource ?. associationLink ) . to . equal ( "/associations/123456" ) ;
450- } ) ;
451- } ) ;
452-
453- it ( "should return 201 response if a new association created for invited user" , async ( ) => {
454- sinon . stub ( requestClient , "httpPost" ) . resolves ( mockPostResponse [ 201 ] ) ;
455- await associationsService . createAssociation ( companyNumber , inviteeEmailAddress ) . then ( ( data ) => {
445+ await associationsService . createAssociation ( companyNumber , userId ) . then ( ( data ) => {
456446 expect ( data . httpStatusCode ) . to . equal ( 201 ) ;
457447 const castedData : Resource < NewAssociationResponse > = data as Resource < NewAssociationResponse > ;
458448 expect ( castedData ) . to . exist ;
@@ -462,62 +452,90 @@ describe("AssociationsService", () => {
462452
463453 it ( "should return 400 response" , async ( ) => {
464454 sinon . stub ( requestClient , "httpPost" ) . resolves ( mockPostResponse [ 400 ] ) ;
465- await associationsService . createAssociation ( companyNumber )
466- . then ( ( data ) => {
467- expect ( data . httpStatusCode ) . to . equal ( 400 ) ;
468- } ) ;
469- } ) ;
470-
471- it ( "should return 400 response for invited user" , async ( ) => {
472- sinon . stub ( requestClient , "httpPost" ) . resolves ( mockPostResponse [ 400 ] ) ;
473- await associationsService . createAssociation ( companyNumber , inviteeEmailAddress )
455+ await associationsService . createAssociation ( companyNumber , userId )
474456 . then ( ( data ) => {
475457 expect ( data . httpStatusCode ) . to . equal ( 400 ) ;
476458 } ) ;
477459 } ) ;
478460
479461 it ( "should return 401 response" , async ( ) => {
480462 sinon . stub ( requestClient , "httpPost" ) . resolves ( mockPostResponse [ 401 ] ) ;
481- await associationsService . createAssociation ( companyNumber )
463+ await associationsService . createAssociation ( companyNumber , userId )
482464 . then ( ( data ) => {
483465 expect ( data . httpStatusCode ) . to . equal ( 401 ) ;
484466 } ) ;
485467 } ) ;
486468
487469 it ( "should return 401 response for invited user" , async ( ) => {
488470 sinon . stub ( requestClient , "httpPost" ) . resolves ( mockPostResponse [ 401 ] ) ;
489- await associationsService . createAssociation ( companyNumber , inviteeEmailAddress ) . then ( ( data ) => {
471+ await associationsService . createAssociation ( companyNumber , userId ) . then ( ( data ) => {
490472 expect ( data . httpStatusCode ) . to . equal ( 401 ) ;
491473 } ) ;
492474 } ) ;
493475
494476 it ( "should return 403 response" , async ( ) => {
495477 sinon . stub ( requestClient , "httpPost" ) . resolves ( mockPostResponse [ 403 ] ) ;
496- await associationsService . createAssociation ( companyNumber )
478+ await associationsService . createAssociation ( companyNumber , userId )
497479 . then ( ( data ) => {
498480 expect ( data . httpStatusCode ) . to . equal ( 403 ) ;
499481 } ) ;
500482 } ) ;
501483
502- it ( "should return 403 response for invited user" , async ( ) => {
503- sinon . stub ( requestClient , "httpPost" ) . resolves ( mockPostResponse [ 403 ] ) ;
484+ it ( "should return 500 response" , async ( ) => {
485+ sinon . stub ( requestClient , "httpPost" ) . resolves ( mockPostResponse [ 500 ] ) ;
486+ await associationsService . createAssociation ( companyNumber , userId )
487+ . then ( ( data ) => {
488+ expect ( data . httpStatusCode ) . to . equal ( 500 ) ;
489+ } ) ;
490+ } ) ;
491+ } ) ;
492+
493+ describe ( "inviteUser" , ( ) => {
494+ let associationsService : AssociationsService ;
495+ const inviteeEmailAddress = "[email protected] " ; 496+
497+ beforeEach ( ( ) => {
498+ sinon . reset ( ) ;
499+ sinon . restore ( ) ;
500+ associationsService = new AssociationsService ( requestClient ) ;
501+ } ) ;
502+
503+ it ( "should return 201 response if a new association created for invited user" , async ( ) => {
504+ sinon . stub ( requestClient , "httpPost" ) . resolves ( mockPostResponse [ 201 ] ) ;
505+ await associationsService . inviteUser ( companyNumber , inviteeEmailAddress ) . then ( ( data ) => {
506+ expect ( data . httpStatusCode ) . to . equal ( 201 ) ;
507+ const castedData : Resource < NewAssociationResponse > = data as Resource < NewAssociationResponse > ;
508+ expect ( castedData ) . to . exist ;
509+ expect ( castedData . resource ?. associationLink ) . to . equal ( "/associations/123456" ) ;
510+ } ) ;
511+ } ) ;
512+
513+ it ( "should return 400 response for invited user" , async ( ) => {
514+ sinon . stub ( requestClient , "httpPost" ) . resolves ( mockPostResponse [ 400 ] ) ;
504515 await associationsService . createAssociation ( companyNumber , inviteeEmailAddress )
505516 . then ( ( data ) => {
506- expect ( data . httpStatusCode ) . to . equal ( 403 ) ;
517+ expect ( data . httpStatusCode ) . to . equal ( 400 ) ;
507518 } ) ;
508519 } ) ;
509520
510- it ( "should return 500 response" , async ( ) => {
511- sinon . stub ( requestClient , "httpPost" ) . resolves ( mockPostResponse [ 500 ] ) ;
512- await associationsService . createAssociation ( companyNumber )
521+ it ( "should return 401 response for invited user" , async ( ) => {
522+ sinon . stub ( requestClient , "httpPost" ) . resolves ( mockPostResponse [ 401 ] ) ;
523+ await associationsService . inviteUser ( companyNumber , inviteeEmailAddress ) . then ( ( data ) => {
524+ expect ( data . httpStatusCode ) . to . equal ( 401 ) ;
525+ } ) ;
526+ } ) ;
527+
528+ it ( "should return 403 response for invited user" , async ( ) => {
529+ sinon . stub ( requestClient , "httpPost" ) . resolves ( mockPostResponse [ 403 ] ) ;
530+ await associationsService . inviteUser ( companyNumber , inviteeEmailAddress )
513531 . then ( ( data ) => {
514- expect ( data . httpStatusCode ) . to . equal ( 500 ) ;
532+ expect ( data . httpStatusCode ) . to . equal ( 403 ) ;
515533 } ) ;
516534 } ) ;
517535
518536 it ( "should return 500 response for invited user" , async ( ) => {
519537 sinon . stub ( requestClient , "httpPost" ) . resolves ( mockPostResponse [ 500 ] ) ;
520- await associationsService . createAssociation ( companyNumber , inviteeEmailAddress )
538+ await associationsService . inviteUser ( companyNumber , inviteeEmailAddress )
521539 . then ( ( data ) => {
522540 expect ( data . httpStatusCode ) . to . equal ( 500 ) ;
523541 } ) ;
0 commit comments