|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative "../lib/embed_workflow" |
| 4 | +require "net/http" |
| 5 | + |
| 6 | +describe "users" do |
| 7 | + before do |
| 8 | + allow_any_instance_of(EmbedWorkflow::Client) |
| 9 | + .to receive(:execute_request) |
| 10 | + .with(instance_of(Net::HTTPRequest)) |
| 11 | + .and_return("response") |
| 12 | + end |
| 13 | + |
| 14 | + describe "#list" do |
| 15 | + before do |
| 16 | + allow_any_instance_of(EmbedWorkflow::Client) |
| 17 | + .to receive(:get_request) |
| 18 | + .with({ path: "/api/v1/users", params: {} }) |
| 19 | + .and_return("response") |
| 20 | + end |
| 21 | + |
| 22 | + it "sends the correct parameters to the users API" do |
| 23 | + EmbedWorkflow::Users.list |
| 24 | + end |
| 25 | + |
| 26 | + context "with pagination parameters" do |
| 27 | + before do |
| 28 | + allow_any_instance_of(EmbedWorkflow::Client) |
| 29 | + .to receive(:get_request) |
| 30 | + .with({ path: "/api/v1/users", params: { starting_after: "550e8400-e29b-41d4-a716-446655440000", limit: 10 } }) |
| 31 | + .and_return("response") |
| 32 | + end |
| 33 | + |
| 34 | + it "sends the correct pagination parameters" do |
| 35 | + EmbedWorkflow::Users.list(starting_after: "550e8400-e29b-41d4-a716-446655440000", limit: 10) |
| 36 | + end |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + describe "#fetch" do |
| 41 | + before do |
| 42 | + allow_any_instance_of(EmbedWorkflow::Client) |
| 43 | + .to receive(:get_request) |
| 44 | + .with({ path: "/api/v1/users/api-user-1" }) |
| 45 | + .and_return("response") |
| 46 | + end |
| 47 | + |
| 48 | + it "sends the correct parameters to the users API" do |
| 49 | + EmbedWorkflow::Users.fetch(key: "api-user-1") |
| 50 | + end |
| 51 | + end |
| 52 | + |
| 53 | + describe "#delete" do |
| 54 | + before do |
| 55 | + allow_any_instance_of(EmbedWorkflow::Client) |
| 56 | + .to receive(:delete_request) |
| 57 | + .with({ path: "/api/v1/users/api-user-1" }) |
| 58 | + .and_return("response") |
| 59 | + end |
| 60 | + |
| 61 | + it "sends the correct parameters to the users API" do |
| 62 | + EmbedWorkflow::Users.delete(key: "api-user-1") |
| 63 | + end |
| 64 | + end |
| 65 | + |
| 66 | + describe "#upsert" do |
| 67 | + context "with minimum parameters" do |
| 68 | + before do |
| 69 | + allow_any_instance_of(EmbedWorkflow::Client) |
| 70 | + .to receive(:put_request) |
| 71 | + .with({ |
| 72 | + path: "/api/v1/users/api-user-1", |
| 73 | + body: { key: "api-user-1" } |
| 74 | + }) |
| 75 | + .and_return("response") |
| 76 | + end |
| 77 | + |
| 78 | + it "sends the correct parameters to the users API" do |
| 79 | + EmbedWorkflow::Users.upsert(key: "api-user-1") |
| 80 | + end |
| 81 | + end |
| 82 | + |
| 83 | + context "with all parameters" do |
| 84 | + before do |
| 85 | + config = { user_data: { foo: "bar" } } |
| 86 | + allow_any_instance_of(EmbedWorkflow::Client) |
| 87 | + .to receive(:put_request) |
| 88 | + .with({ |
| 89 | + path: "/api/v1/users/api-user-1", |
| 90 | + body: { |
| 91 | + key: "api-user-1", |
| 92 | + name: "Jane Doe", |
| 93 | + email: "jane@example.com", |
| 94 | + config: config |
| 95 | + } |
| 96 | + }) |
| 97 | + .and_return("response") |
| 98 | + end |
| 99 | + |
| 100 | + it "sends the correct parameters to the users API" do |
| 101 | + config = { user_data: { foo: "bar" } } |
| 102 | + EmbedWorkflow::Users.upsert( |
| 103 | + key: "api-user-1", |
| 104 | + name: "Jane Doe", |
| 105 | + email: "jane@example.com", |
| 106 | + config: config |
| 107 | + ) |
| 108 | + end |
| 109 | + end |
| 110 | + end |
| 111 | +end |
0 commit comments