@@ -786,6 +786,104 @@ public function testUpdateProjectServiceStatus($data): void
786
786
}
787
787
}
788
788
789
+ /** @depends testUpdateProjectServiceStatusAdmin */
790
+ public function testUpdateProjectServiceStatusServer ($ data ): void
791
+ {
792
+ $ id = $ data ['projectId ' ];
793
+
794
+ $ services = require ('app/config/services.php ' );
795
+
796
+ /**
797
+ * Test for Disabled
798
+ */
799
+ foreach ($ services as $ service ) {
800
+ if (!$ service ['optional ' ]) {
801
+ continue ;
802
+ }
803
+
804
+ $ key = $ service ['key ' ] ?? '' ;
805
+
806
+ $ response = $ this ->client ->call (Client::METHOD_PATCH , '/projects/ ' . $ id . '/service ' , array_merge ([
807
+ 'content-type ' => 'application/json ' ,
808
+ 'x-appwrite-project ' => $ this ->getProject ()['$id ' ],
809
+ 'cookie ' => 'a_session_console= ' . $ this ->getRoot ()['session ' ],
810
+ ]), [
811
+ 'service ' => $ key ,
812
+ 'status ' => false ,
813
+ ]);
814
+
815
+ $ this ->assertEquals (200 , $ response ['headers ' ]['status-code ' ]);
816
+ $ this ->assertNotEmpty ($ response ['body ' ]['$id ' ]);
817
+
818
+ $ response = $ this ->client ->call (Client::METHOD_GET , '/projects/ ' . $ id , array_merge ([
819
+ 'content-type ' => 'application/json ' ,
820
+ 'x-appwrite-project ' => $ this ->getProject ()['$id ' ],
821
+ 'cookie ' => 'a_session_console= ' . $ this ->getRoot ()['session ' ],
822
+ ]));
823
+
824
+ $ this ->assertEquals (200 , $ response ['headers ' ]['status-code ' ]);
825
+ $ this ->assertNotEmpty ($ response ['body ' ]['$id ' ]);
826
+ $ this ->assertEquals (false , $ response ['body ' ]['serviceStatusFor ' . ucfirst ($ key )]);
827
+ }
828
+
829
+ // Create API Key
830
+ $ response = $ this ->client ->call (Client::METHOD_POST , '/projects/ ' . $ id . '/keys ' , array_merge ([
831
+ 'content-type ' => 'application/json ' ,
832
+ 'x-appwrite-project ' => $ this ->getProject ()['$id ' ],
833
+ 'cookie ' => 'a_session_console= ' . $ this ->getRoot ()['session ' ],
834
+ ]), [
835
+ 'name ' => 'Key Test ' ,
836
+ 'scopes ' => ['functions.read ' , 'teams.write ' ],
837
+ ]);
838
+
839
+ $ this ->assertEquals (201 , $ response ['headers ' ]['status-code ' ]);
840
+
841
+ $ keyId = $ response ['body ' ]['$id ' ];
842
+ $ keySecret = $ response ['body ' ]['secret ' ];
843
+
844
+ /**
845
+ * Request with API Key must succeed
846
+ */
847
+ $ response = $ this ->client ->call (Client::METHOD_GET , '/functions ' , array_merge ([
848
+ 'content-type ' => 'application/json ' ,
849
+ 'x-appwrite-project ' => $ id ,
850
+ 'x-appwrite-key ' => $ keySecret ,
851
+ ]));
852
+
853
+ $ this ->assertEquals (200 , $ response ['headers ' ]['status-code ' ]);
854
+
855
+ $ response = $ this ->client ->call (Client::METHOD_POST , '/teams ' , array_merge ([
856
+ 'content-type ' => 'application/json ' ,
857
+ 'x-appwrite-project ' => $ id ,
858
+ 'x-appwrite-key ' => $ keySecret ,
859
+ ]), [
860
+ 'teamId ' => 'unique() ' ,
861
+ 'name ' => 'Arsenal '
862
+ ]);
863
+
864
+ $ this ->assertEquals (201 , $ response ['headers ' ]['status-code ' ]);
865
+
866
+ // Cleanup
867
+
868
+ $ response = $ this ->client ->call (Client::METHOD_DELETE , '/projects/ ' . $ id . '/keys/ ' . $ keyId , array_merge ([
869
+ 'content-type ' => 'application/json ' ,
870
+ 'x-appwrite-project ' => $ this ->getProject ()['$id ' ],
871
+ 'cookie ' => 'a_session_console= ' . $ this ->getRoot ()['session ' ],
872
+ ]), []);
873
+
874
+ $ this ->assertEquals (204 , $ response ['headers ' ]['status-code ' ]);
875
+
876
+ foreach ($ services as $ service ) {
877
+ $ response = $ this ->client ->call (Client::METHOD_PATCH , '/projects/ ' . $ id . '/service/ ' , array_merge ([
878
+ 'content-type ' => 'application/json ' ,
879
+ 'x-appwrite-project ' => $ this ->getProject ()['$id ' ],
880
+ ], $ this ->getHeaders ()), [
881
+ 'service ' => $ service ,
882
+ 'status ' => true ,
883
+ ]);
884
+ }
885
+ }
886
+
789
887
/**
790
888
* @depends testCreateProject
791
889
*/
0 commit comments