|
2 | 2 |
|
3 | 3 | describe Layer::Resources::User do |
4 | 4 | let(:client) { Layer::Platform::Client.new } |
| 5 | + let(:http_client) { instance_double("Layer::HttpClient") } |
| 6 | + let(:user) { client.users.find("some_user") } |
| 7 | + |
| 8 | + before do |
| 9 | + allow(client).to receive(:client).and_return(http_client) |
| 10 | + end |
5 | 11 |
|
6 | 12 | describe ".find" do |
7 | 13 | it "should return instance of User" do |
8 | | - user = client.users.find("jake") |
9 | 14 | expect(user).to be_instance_of(described_class) |
10 | 15 | end |
11 | 16 |
|
12 | 17 | it "shouldn't send any request" do |
13 | 18 | expect(Layer::HttpClient).to_not receive(:find) |
14 | | - client.users.find("jake") |
| 19 | + user |
15 | 20 | end |
16 | 21 | end |
17 | 22 |
|
18 | 23 | describe "#blocks" do |
19 | 24 | it "should instantiate new ResourceProxy for Block" do |
20 | | - user = client.users.find("jake") |
21 | 25 | blocks = user.blocks |
22 | 26 | base = blocks.instance_variable_get("@base") |
23 | 27 | resource = blocks.instance_variable_get("@resource") |
|
30 | 34 |
|
31 | 35 | describe "#conversations" do |
32 | 36 | it "should instantiate new ResourceProxy for Conversation" do |
33 | | - user = client.users.find("jake") |
34 | 37 | conversations = user.conversations |
35 | 38 | base = conversations.instance_variable_get("@base") |
36 | 39 | resource = conversations.instance_variable_get("@resource") |
|
43 | 46 |
|
44 | 47 | describe "#messages" do |
45 | 48 | it "should instantiate new ResourceProxy for Message" do |
46 | | - user = client.users.find("jake") |
47 | 49 | messages = user.messages |
48 | 50 | base = messages.instance_variable_get("@base") |
49 | 51 | resource = messages.instance_variable_get("@resource") |
|
53 | 55 | expect(resource).to eq(Layer::Resources::Message) |
54 | 56 | end |
55 | 57 | end |
| 58 | + |
| 59 | + describe "#create_identity" do |
| 60 | + it "should create identity for a user" do |
| 61 | + allow(http_client).to receive(:post).and_return("") |
| 62 | + expect(http_client).to receive(:post). |
| 63 | + with("users/#{user.id}/identity", body: user_identity_params.to_json) |
| 64 | + |
| 65 | + user.create_identity(user_identity_params) |
| 66 | + end |
| 67 | + end |
| 68 | + |
| 69 | + describe "#identity" do |
| 70 | + before do |
| 71 | + allow(http_client).to receive(:get).and_return(user_identity_params) |
| 72 | + expect(http_client).to receive(:get).with("users/#{user.id}/identity") |
| 73 | + end |
| 74 | + |
| 75 | + it "should retrieve the users identity" do |
| 76 | + user.identity |
| 77 | + end |
| 78 | + |
| 79 | + it "should return a hash containing the users identity" do |
| 80 | + identity = user.identity |
| 81 | + expect(identity).to be_instance_of(Hash) |
| 82 | + end |
| 83 | + end |
| 84 | + |
| 85 | + describe "#update_identity" do |
| 86 | + let(:patch_header) { { 'Content-Type' => 'application/vnd.layer-patch+json' } } |
| 87 | + |
| 88 | + it "should update the users identity" do |
| 89 | + allow(http_client).to receive(:patch).and_return("") |
| 90 | + allow(http_client).to receive(:layer_patch_header).and_return(patch_header) |
| 91 | + |
| 92 | + expect(http_client).to receive(:patch). |
| 93 | + with( |
| 94 | + "users/#{user.id}/identity", |
| 95 | + body: user_identity_operations.to_json, |
| 96 | + headers: patch_header |
| 97 | + ) |
| 98 | + |
| 99 | + user.update_identity(user_identity_operations) |
| 100 | + end |
| 101 | + end |
| 102 | + |
| 103 | + describe "#replace_identity" do |
| 104 | + it "should replace the users identity" do |
| 105 | + allow(http_client).to receive(:put).and_return("") |
| 106 | + expect(http_client).to receive(:put). |
| 107 | + with( |
| 108 | + "users/#{user.id}/identity", |
| 109 | + body: user_identity_params.to_json |
| 110 | + ) |
| 111 | + |
| 112 | + user.replace_identity(user_identity_params) |
| 113 | + end |
| 114 | + end |
| 115 | + |
| 116 | + describe "#delete_identity" do |
| 117 | + it "should make a request to delete the users identity" do |
| 118 | + allow(http_client).to receive(:delete).and_return("") |
| 119 | + expect(http_client).to receive(:delete).with("users/#{user.id}/identity") |
| 120 | + |
| 121 | + user.destroy_identity |
| 122 | + end |
| 123 | + end |
56 | 124 | end |
0 commit comments