Skip to content

Commit 389bf6c

Browse files
committed
feat(orders): expose order execution record on the api
1 parent ab5ada5 commit 389bf6c

9 files changed

Lines changed: 172 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
module Types
4+
module Orders
5+
class ExecutionRecord < Types::BaseObject
6+
graphql_name "OrderExecutionRecord"
7+
8+
field :errors, [String], null: false
9+
field :executed_at, String, null: true
10+
field :execution_mode, Types::Orders::ExecutionModeEnum, null: true
11+
field :invoice_id, ID, null: true
12+
13+
def errors
14+
object["errors"] || []
15+
end
16+
end
17+
end
18+
end

app/graphql/types/orders/object.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Object < Types::BaseObject
1515
field :currency, String, null: true
1616
field :execute_at, GraphQL::Types::ISO8601DateTime, null: true
1717
field :executed_at, GraphQL::Types::ISO8601DateTime, null: true
18+
field :execution_record, Types::Orders::ExecutionRecord, null: false
1819

1920
field :customer, Types::Customers::Object, null: false
2021
field :order_form, Types::OrderForms::Object, null: false

app/serializers/v1/order_serializer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def serialize
1212
billing_snapshot: model.billing_snapshot,
1313
currency: model.currency,
1414
executed_at: model.executed_at&.iso8601,
15+
execution_record: model.execution_record,
1516
lago_organization_id: model.organization_id,
1617
lago_customer_id: model.customer_id,
1718
lago_order_form_id: model.order_form_id,

schema.graphql

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schema.json

Lines changed: 87 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/graphql/resolvers/order_resolver_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
orderType
1616
createdAt
1717
updatedAt
18+
executionRecord { errors executionMode invoiceId executedAt }
1819
}
1920
}
2021
GQL
@@ -48,6 +49,30 @@
4849
expect(data["number"]).to eq(order.number)
4950
expect(data["status"]).to eq("created")
5051
expect(data["orderType"]).to eq("subscription_creation")
52+
expect(data["executionRecord"]).to eq(
53+
"errors" => [], "executionMode" => nil, "invoiceId" => nil, "executedAt" => nil
54+
)
55+
end
56+
57+
context "when the order failed" do
58+
let(:order) { create(:order, :failed, organization:, customer:, order_form:) }
59+
60+
it "resolves the execution record trace" do
61+
result = execute_graphql(
62+
current_user: membership.user,
63+
current_organization: organization,
64+
permissions: required_permission,
65+
query:,
66+
variables: {id: order.id}
67+
)
68+
69+
record = result["data"]["order"]["executionRecord"]
70+
71+
expect(record["errors"]).to eq(["currencies_does_not_match"])
72+
expect(record["executionMode"]).to eq("execute_in_lago")
73+
expect(record["invoiceId"]).to be_nil
74+
expect(record["executedAt"]).to be_nil
75+
end
5176
end
5277

5378
context "when order is not found" do
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
RSpec.describe Types::Orders::ExecutionRecord do
6+
subject { described_class }
7+
8+
it do
9+
expect(subject).to have_field(:errors).of_type("[String!]!")
10+
expect(subject).to have_field(:executed_at).of_type("String")
11+
expect(subject).to have_field(:execution_mode).of_type("OrderExecutionModeEnum")
12+
expect(subject).to have_field(:invoice_id).of_type("ID")
13+
end
14+
end

spec/graphql/types/orders/object_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
expect(subject).to have_field(:currency).of_type("String")
1717
expect(subject).to have_field(:execute_at).of_type("ISO8601DateTime")
1818
expect(subject).to have_field(:executed_at).of_type("ISO8601DateTime")
19+
expect(subject).to have_field(:execution_record).of_type("OrderExecutionRecord!")
1920

2021
expect(subject).to have_field(:customer).of_type("Customer!")
2122
expect(subject).to have_field(:order_form).of_type("OrderForm!")

spec/serializers/v1/order_serializer_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,28 @@
2424
"billing_snapshot" => order.billing_snapshot,
2525
"currency" => "EUR",
2626
"executed_at" => nil,
27+
"execution_record" => order.execution_record,
2728
"lago_organization_id" => order.organization_id,
2829
"lago_customer_id" => order.customer_id,
2930
"lago_order_form_id" => order.order_form_id,
3031
"created_at" => order.created_at.iso8601,
3132
"updated_at" => order.updated_at.iso8601
3233
)
3334
end
35+
36+
context "when the order failed" do
37+
let(:order) { create(:order, :failed, organization:, customer:, order_form:) }
38+
39+
it "serializes the execution record trace" do
40+
result = JSON.parse(serializer.to_json)
41+
42+
expect(result["order"]["status"]).to eq("failed")
43+
expect(result["order"]["execution_record"]).to eq(
44+
"executed_at" => nil,
45+
"execution_mode" => "execute_in_lago",
46+
"invoice_id" => nil,
47+
"errors" => ["currencies_does_not_match"]
48+
)
49+
end
50+
end
3451
end

0 commit comments

Comments
 (0)