Skip to content

Conversation

groyoh
Copy link
Contributor

@groyoh groyoh commented Jul 8, 2025

Context

While working on the Subscriptions::UpdateService, I noticed some test cases missing so I decided to add them. Adding the following spec failed:

      context "when specifying only name" do
        let(:subscription) { create(:subscription, customer:) }
        let(:params) { {name: "new name"} }

        it "updates the subscription" do
          result = update_service.call

          expect(result).to be_success

          expect(result.subscription.name).to eq("new name")
          expect(result.subscription.subscription_at.to_s).not_to include("2022-07-07")
        end
      end

This is due to the fact that subscription_at is nil in the factory but:

  1. It is expected to be set in the Subscriptions::UpdateService
  2. It is always set when creating a subscription
    @subscription_at = params[:subscription_at] || Time.current

Description

This PR add a default subscription_at to the subscription factory.

@groyoh groyoh changed the title chore(factory): Add subscription_at to subscription factory test(factory): Add subscription_at to subscription factory Jul 8, 2025
@groyoh groyoh marked this pull request as ready for review July 8, 2025 16:04
@groyoh groyoh merged commit 6d5f753 into main Jul 9, 2025
14 checks passed
@groyoh groyoh deleted the chore/subscription-factory branch July 9, 2025 06:45
diegocharles pushed a commit that referenced this pull request Jul 11, 2025
## Context

While working on the `Subscriptions::UpdateService`, I noticed some test cases missing so I decided to add them. Adding the following spec failed:

```ruby
      context "when specifying only name" do
        let(:subscription) { create(:subscription, customer:) }
        let(:params) { {name: "new name"} }

        it "updates the subscription" do
          result = update_service.call

          expect(result).to be_success

          expect(result.subscription.name).to eq("new name")
          expect(result.subscription.subscription_at.to_s).not_to include("2022-07-07")
        end
      end
```

This is due to the fact that `subscription_at` is `nil` in the factory but:

1. It is expected to be set in the `Subscriptions::UpdateService`
2. It is always set when creating a subscription https://github.com/getlago/lago-api/blob/9eebd429260041b822b1bf46abf51a2b200a54b9/app/services/subscriptions/create_service.rb#L13

## Description

This commit adds a default `subscription_at` to the `subscription` factory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants