@@ -490,3 +490,192 @@ func TestClient_AppsDatastoreGet(t *testing.T) {
490490 })
491491 }
492492}
493+
494+ func TestClient_AppsDatastoreBulkPut (t * testing.T ) {
495+ tests := map [string ]struct {
496+ request types.AppDatastoreBulkPut
497+ httpResponseJSON string
498+ statusCode int
499+ wantErr bool
500+ errMessage string
501+ }{
502+ "success" : {
503+ request : types.AppDatastoreBulkPut {
504+ Datastore : "my_ds" ,
505+ App : "A1" ,
506+ Items : []map [string ]interface {}{{"id" : "1" , "name" : "test" }},
507+ },
508+ httpResponseJSON : `{"ok":true,"datastore":"my_ds"}` ,
509+ },
510+ "api_error" : {
511+ request : types.AppDatastoreBulkPut {
512+ Datastore : "my_ds" ,
513+ App : "A1" ,
514+ Items : []map [string ]interface {}{{"id" : "1" }},
515+ },
516+ httpResponseJSON : `{"ok":false,"error":"datastore_error"}` ,
517+ wantErr : true ,
518+ errMessage : "datastore_error" ,
519+ },
520+ }
521+ for name , tc := range tests {
522+ t .Run (name , func (t * testing.T ) {
523+ ctx := slackcontext .MockContext (t .Context ())
524+ c , teardown := NewFakeClient (t , FakeClientParams {
525+ ExpectedMethod : appDatastoreBulkPutMethod ,
526+ Response : tc .httpResponseJSON ,
527+ StatusCode : tc .statusCode ,
528+ })
529+ defer teardown ()
530+ _ , err := c .AppsDatastoreBulkPut (ctx , "token" , tc .request )
531+ if tc .wantErr {
532+ require .Error (t , err )
533+ require .Contains (t , err .Error (), tc .errMessage )
534+ } else {
535+ require .NoError (t , err )
536+ }
537+ })
538+ }
539+ }
540+
541+ func TestClient_AppsDatastoreCount (t * testing.T ) {
542+ tests := map [string ]struct {
543+ request types.AppDatastoreCount
544+ httpResponseJSON string
545+ statusCode int
546+ wantCount int
547+ wantErr bool
548+ errMessage string
549+ }{
550+ "success" : {
551+ request : types.AppDatastoreCount {
552+ Datastore : "my_ds" ,
553+ App : "A1" ,
554+ },
555+ httpResponseJSON : `{"ok":true,"datastore":"my_ds","count":42}` ,
556+ wantCount : 42 ,
557+ },
558+ "api_error" : {
559+ request : types.AppDatastoreCount {
560+ Datastore : "my_ds" ,
561+ App : "A1" ,
562+ },
563+ httpResponseJSON : `{"ok":false,"error":"datastore_error"}` ,
564+ wantErr : true ,
565+ errMessage : "datastore_error" ,
566+ },
567+ }
568+ for name , tc := range tests {
569+ t .Run (name , func (t * testing.T ) {
570+ ctx := slackcontext .MockContext (t .Context ())
571+ c , teardown := NewFakeClient (t , FakeClientParams {
572+ ExpectedMethod : appDatastoreCountMethod ,
573+ Response : tc .httpResponseJSON ,
574+ StatusCode : tc .statusCode ,
575+ })
576+ defer teardown ()
577+ got , err := c .AppsDatastoreCount (ctx , "token" , tc .request )
578+ if tc .wantErr {
579+ require .Error (t , err )
580+ require .Contains (t , err .Error (), tc .errMessage )
581+ } else {
582+ require .NoError (t , err )
583+ require .Equal (t , tc .wantCount , got .Count )
584+ }
585+ })
586+ }
587+ }
588+
589+ func TestClient_AppsDatastoreBulkDelete (t * testing.T ) {
590+ tests := map [string ]struct {
591+ request types.AppDatastoreBulkDelete
592+ httpResponseJSON string
593+ statusCode int
594+ wantErr bool
595+ errMessage string
596+ }{
597+ "success" : {
598+ request : types.AppDatastoreBulkDelete {
599+ Datastore : "my_ds" ,
600+ App : "A1" ,
601+ IDs : []string {"id1" , "id2" },
602+ },
603+ httpResponseJSON : `{"ok":true}` ,
604+ },
605+ "api_error" : {
606+ request : types.AppDatastoreBulkDelete {
607+ Datastore : "my_ds" ,
608+ App : "A1" ,
609+ IDs : []string {"id1" },
610+ },
611+ httpResponseJSON : `{"ok":false,"error":"not_found"}` ,
612+ wantErr : true ,
613+ errMessage : "not_found" ,
614+ },
615+ }
616+ for name , tc := range tests {
617+ t .Run (name , func (t * testing.T ) {
618+ ctx := slackcontext .MockContext (t .Context ())
619+ c , teardown := NewFakeClient (t , FakeClientParams {
620+ ExpectedMethod : appDatastoreBulkDeleteMethod ,
621+ Response : tc .httpResponseJSON ,
622+ StatusCode : tc .statusCode ,
623+ })
624+ defer teardown ()
625+ _ , err := c .AppsDatastoreBulkDelete (ctx , "token" , tc .request )
626+ if tc .wantErr {
627+ require .Error (t , err )
628+ require .Contains (t , err .Error (), tc .errMessage )
629+ } else {
630+ require .NoError (t , err )
631+ }
632+ })
633+ }
634+ }
635+
636+ func TestClient_AppsDatastoreBulkGet (t * testing.T ) {
637+ tests := map [string ]struct {
638+ request types.AppDatastoreBulkGet
639+ httpResponseJSON string
640+ statusCode int
641+ wantErr bool
642+ errMessage string
643+ }{
644+ "success" : {
645+ request : types.AppDatastoreBulkGet {
646+ Datastore : "my_ds" ,
647+ App : "A1" ,
648+ IDs : []string {"id1" , "id2" },
649+ },
650+ httpResponseJSON : `{"ok":true,"datastore":"my_ds","items":[{"id":"id1","name":"test"}]}` ,
651+ },
652+ "api_error" : {
653+ request : types.AppDatastoreBulkGet {
654+ Datastore : "my_ds" ,
655+ App : "A1" ,
656+ IDs : []string {"id1" },
657+ },
658+ httpResponseJSON : `{"ok":false,"error":"not_found"}` ,
659+ wantErr : true ,
660+ errMessage : "not_found" ,
661+ },
662+ }
663+ for name , tc := range tests {
664+ t .Run (name , func (t * testing.T ) {
665+ ctx := slackcontext .MockContext (t .Context ())
666+ c , teardown := NewFakeClient (t , FakeClientParams {
667+ ExpectedMethod : appDatastoreBulkGetMethod ,
668+ Response : tc .httpResponseJSON ,
669+ StatusCode : tc .statusCode ,
670+ })
671+ defer teardown ()
672+ _ , err := c .AppsDatastoreBulkGet (ctx , "token" , tc .request )
673+ if tc .wantErr {
674+ require .Error (t , err )
675+ require .Contains (t , err .Error (), tc .errMessage )
676+ } else {
677+ require .NoError (t , err )
678+ }
679+ })
680+ }
681+ }
0 commit comments