Skip to content

fix(structures): add missing toJSON method on Subscription structure#11431

Merged
kodiakhq[bot] merged 2 commits intodiscordjs:mainfrom
AsadHumayun:fix/add-tojson-subscription-structure
Mar 1, 2026
Merged

fix(structures): add missing toJSON method on Subscription structure#11431
kodiakhq[bot] merged 2 commits intodiscordjs:mainfrom
AsadHumayun:fix/add-tojson-subscription-structure

Conversation

@AsadHumayun
Copy link
Contributor

When writing tests for #11407, it became apparent that I had forgotten to add the toJSON method for this structure when I initially wrote the structure. I have now added this method and it passes when running the tests that I have written for this (which will be merged in a following PR).

Apologies for having missed this the first time.

When writing tests for discordjs#11407, it became apparent that I had forgotten to add the `toJSON` method for this structure when I was initially wrote the structure. I have now added this method and it passes when running the tests that I have written for this (which will be merged in a following PR).

Signed-off-by: Asad Humayun <asad.humayun@asadh.io>
@vercel
Copy link

vercel bot commented Feb 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
discord-js Skipped Skipped Mar 1, 2026 9:07pm
discord-js-guide Skipped Skipped Mar 1, 2026 9:07pm

Request Review

@vercel vercel bot temporarily deployed to Preview – discord-js February 27, 2026 21:52 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js-guide February 27, 2026 21:52 Inactive
@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0cb8be4 and 74be05b.

📒 Files selected for processing (1)
  • packages/structures/src/subscriptions/Subscription.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Tests
🧰 Additional context used
🧬 Code graph analysis (1)
packages/structures/src/subscriptions/Subscription.ts (2)
packages/structures/src/utils/symbols.ts (3)
  • kCurrentPeriodStartTimestamp (13-13)
  • kCurrentPeriodEndTimestamp (14-14)
  • kCanceledTimestamp (15-15)
packages/structures/src/utils/optimization.ts (1)
  • dateToDiscordISOTimestamp (20-22)
🔇 Additional comments (2)
packages/structures/src/subscriptions/Subscription.ts (2)

4-4: LGTM!

Import is correctly added for the utility function used in the new toJSON() method.


182-202: LGTM!

The toJSON() implementation correctly reconstructs the full APISubscription representation by:

  1. Cloning the base data via super.toJSON()
  2. Re-adding the optimized timestamp fields in Discord's expected ISO format

The null-safety checks are appropriate since these timestamps are stored as number | null.


📝 Walkthrough

Walkthrough

A new toJSON() method override is added to the Subscription class that augments the base JSON serialization with ISO-formatted timestamp fields (current_period_end, current_period_start, canceled_at) derived from internal timestamp properties.

Changes

Cohort / File(s) Summary
Subscription JSON Serialization
packages/structures/src/subscriptions/Subscription.ts
Added toJSON() override method that extends base JSON with ISO-formatted timestamp conversions for period and cancellation dates using dateToDiscordISOTimestamp utility.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a missing toJSON method to the Subscription structure, which directly matches the changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining the context of the missing toJSON method and its discovery during testing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 31.63%. Comparing base (0cb8be4) to head (2ffb120).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...kages/structures/src/subscriptions/Subscription.ts 0.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11431      +/-   ##
==========================================
- Coverage   31.66%   31.63%   -0.03%     
==========================================
  Files         386      386              
  Lines       13966    13978      +12     
  Branches     1098     1101       +3     
==========================================
  Hits         4422     4422              
- Misses       9410     9422      +12     
  Partials      134      134              
Flag Coverage Δ
structures 34.74% <0.00%> (-0.29%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

AsadHumayun added a commit to AsadHumayun/discord.js that referenced this pull request Feb 28, 2026
@github-project-automation github-project-automation bot moved this from Todo to Review Approved in discord.js Mar 1, 2026
@vercel vercel bot temporarily deployed to Preview – discord-js-guide March 1, 2026 21:07 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js March 1, 2026 21:07 Inactive
@kodiakhq kodiakhq bot merged commit fce4989 into discordjs:main Mar 1, 2026
8 checks passed
@github-project-automation github-project-automation bot moved this from Review Approved to Done in discord.js Mar 1, 2026
AsadHumayun added a commit to AsadHumayun/discord.js that referenced this pull request Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants