|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | require_relative "../lib/embed_workflow" |
| 4 | +require "net/http" |
4 | 5 |
|
5 | 6 | describe "workflows" do |
6 | 7 | before do |
7 | | - EmbedWorkflow.skey = "sk_live_REPLACE_ME" |
| 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/workflows", params: {} }) |
| 19 | + .and_return("response") |
| 20 | + end |
| 21 | + |
| 22 | + it "sends the correct parameters to the workflows API" do |
| 23 | + EmbedWorkflow::Workflows.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({ |
| 31 | + path: "/api/v1/workflows", |
| 32 | + params: { |
| 33 | + starting_after: "550e8400-e29b-41d4-a716-446655440000", |
| 34 | + limit: 10 |
| 35 | + } |
| 36 | + }) |
| 37 | + .and_return("response") |
| 38 | + end |
| 39 | + |
| 40 | + it "sends the correct pagination parameters" do |
| 41 | + EmbedWorkflow::Workflows.list( |
| 42 | + starting_after: "550e8400-e29b-41d4-a716-446655440000", |
| 43 | + limit: 10 |
| 44 | + ) |
| 45 | + end |
| 46 | + end |
| 47 | + |
| 48 | + context "with user_key parameter" do |
| 49 | + before do |
| 50 | + allow_any_instance_of(EmbedWorkflow::Client) |
| 51 | + .to receive(:get_request) |
| 52 | + .with({ |
| 53 | + path: "/api/v1/workflows", |
| 54 | + params: { user_key: "api-user-1" } |
| 55 | + }) |
| 56 | + .and_return("response") |
| 57 | + end |
| 58 | + |
| 59 | + it "sends the correct user_key parameter" do |
| 60 | + EmbedWorkflow::Workflows.list(user_key: "api-user-1") |
| 61 | + end |
| 62 | + end |
8 | 63 | end |
9 | 64 | end |
0 commit comments