From 3a282084a01bca924ddfef5cb3a803c9a5b24671 Mon Sep 17 00:00:00 2001 From: Peter Bouda Date: Tue, 15 Oct 2024 10:48:23 +0100 Subject: [PATCH] DEV: Add integration tests for group endpoints --- spec/integration/groups_spec.rb | 102 ++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 spec/integration/groups_spec.rb diff --git a/spec/integration/groups_spec.rb b/spec/integration/groups_spec.rb new file mode 100644 index 0000000..40ad710 --- /dev/null +++ b/spec/integration/groups_spec.rb @@ -0,0 +1,102 @@ +# frozen_string_literal: true + +describe "Group SCIM endpoints" do + before do + SiteSetting.chat_enabled = true + SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:everyone] + end + + fab!(:admin) + + let(:scim_api_key) do + key = ApiKey.create! + ApiKeyScope.create!(resource: "scim", action: "access_scim_endpoints", api_key_id: key.id) + key + end + + def create_group + post "/scim_v2/Groups", + headers: { + "Authorization" => "Bearer " + scim_api_key.key, + "Content-Type" => "application/scim+json" + }, + params: { + schemas: [ + "urn:ietf:params:scim:schemas:core:2.0:Group" + ], + displayName: "TestGroup", + members: [ + { "value": "1"} + ] + }, + as: :json + end + + it "can create a group" do + expect { + create_group + }.to change { Group.count }.by(1) + expect(response.status).to eq(201) + end + + it "can query a group" do + create_group + response_content = JSON.parse(response.body) + get "/scim_v2/Groups/#{response_content["id"]}", + headers: { + "Authorization" => "Bearer " + scim_api_key.key, + "Content-Type" => "application/scim+json" + }, + as: :json + expect(response.status).to eq(200) + response_content = JSON.parse(response.body) + expect(response_content["displayName"]).to eq("TestGroup") + end + + it "can modify a group" do + create_group + response_content = JSON.parse(response.body) + patch "/scim_v2/Groups/#{response_content["id"]}", + headers: { + "Authorization" => "Bearer " + scim_api_key.key, + "Content-Type" => "application/scim+json" + }, + params: { + schemas: [ + "urn:ietf:params:scim:schemas:core:2.0:PatchOp" + ], + Operations: [ + { + op: "replace", + value: { + displayName: "ChangedName" + } + } + ] + }, + as: :json + expect(response.status).to eq(200) + + get "/scim_v2/Groups/#{response_content["id"]}", + headers: { + "Authorization" => "Bearer " + scim_api_key.key, + "Content-Type" => "application/scim+json" + }, + as: :json + expect(response.status).to eq(200) + response_content = JSON.parse(response.body) + expect(response_content["displayName"]).to eq("ChangedName") + end + + it "can delete a group" do + create_group + response_content = JSON.parse(response.body) + delete "/scim_v2/Groups/#{response_content["id"]}", + headers: { + "Authorization" => "Bearer " + scim_api_key.key, + "Content-Type" => "application/scim+json" + }, + as: :json + expect(response.status).to eq(204) + end +end