Commit 494cca1b57f621839b2e7243cc28b407a3f1893e
1 parent
38a739dc
Exists in
master
add http request content-type specs
Showing
1 changed file
with
51 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,51 @@ | @@ -0,0 +1,51 @@ | ||
1 | +require "spec_helper" | ||
2 | + | ||
3 | +RSpec.describe ScimRails::ScimUsersController, type: :request do | ||
4 | + let(:company) { create(:company) } | ||
5 | + let(:credentials) { Base64::encode64("#{company.subdomain}:#{company.api_token}") } | ||
6 | + let(:authorization) { "Basic #{credentials}" } | ||
7 | + | ||
8 | + def post_request(content_type) | ||
9 | + # params need to be transformed into a string to test if they are being parsed by Rack | ||
10 | + | ||
11 | + post "/scim_rails/scim/v2/Users", | ||
12 | + params: { | ||
13 | + name: { | ||
14 | + givenName: "New", | ||
15 | + familyName: "User" | ||
16 | + }, | ||
17 | + emails: [ | ||
18 | + { | ||
19 | + value: "new@example.com" | ||
20 | + } | ||
21 | + ] | ||
22 | + }.to_json, | ||
23 | + headers: { | ||
24 | + 'Authorization': authorization, | ||
25 | + 'Content-Type': content_type | ||
26 | + } | ||
27 | + end | ||
28 | + | ||
29 | + describe "Content-Type" do | ||
30 | + it "accepts scim+json" do | ||
31 | + expect(company.users.count).to eq 0 | ||
32 | + | ||
33 | + post_request("application/scim+json") | ||
34 | + | ||
35 | + expect(request.params).to include :name | ||
36 | + expect(response.status).to eq 201 | ||
37 | + expect(response.content_type).to eq "application/scim+json, application/json" | ||
38 | + expect(company.users.count).to eq 1 | ||
39 | + end | ||
40 | + | ||
41 | + it "can not parse unfamiliar content types" do | ||
42 | + expect(company.users.count).to eq 0 | ||
43 | + | ||
44 | + post_request("invalid_type") | ||
45 | + | ||
46 | + expect(request.params).not_to include :name | ||
47 | + expect(response.status).to eq 422 | ||
48 | + expect(company.users.count).to eq 0 | ||
49 | + end | ||
50 | + end | ||
51 | +end |