|
| 1 | +import type { UpdateGroup } from '../src/types' |
| 2 | +import { describe, expect, it } from 'bun:test' |
| 3 | +import { PullRequestGenerator } from '../src/pr/pr-generator' |
| 4 | + |
| 5 | +describe('PR Body Generation for Major Updates', () => { |
| 6 | + const generator = new PullRequestGenerator() |
| 7 | + |
| 8 | + describe('single major update issue reproduction', () => { |
| 9 | + it('should generate complete PR body for major stripe update (original issue)', async () => { |
| 10 | + // This test reproduces the exact scenario from the user's issue |
| 11 | + const majorStripeUpdate: UpdateGroup = { |
| 12 | + name: 'Major Update - stripe', |
| 13 | + updateType: 'major', |
| 14 | + title: 'chore(deps): update dependency stripe to 18.4.0', |
| 15 | + body: '', |
| 16 | + updates: [{ |
| 17 | + name: 'stripe', |
| 18 | + currentVersion: '17.7.0', |
| 19 | + newVersion: '18.4.0', |
| 20 | + updateType: 'major', |
| 21 | + dependencyType: 'dependencies', |
| 22 | + file: 'package.json', |
| 23 | + metadata: undefined, |
| 24 | + }], |
| 25 | + } |
| 26 | + |
| 27 | + const body = await generator.generateBody(majorStripeUpdate) |
| 28 | + |
| 29 | + // Should NOT be like the broken version: |
| 30 | + // | Type | Count | |
| 31 | + // |------|-------| |
| 32 | + // | **Total** | **1** | |
| 33 | + |
| 34 | + // Should BE like Renovate's format: |
| 35 | + // | Type | Count | |
| 36 | + // |------|-------| |
| 37 | + // | 📦 NPM Packages | 1 | |
| 38 | + // | **Total** | **1** | |
| 39 | + |
| 40 | + expect(body).toContain('## 📦 Package Updates Summary') |
| 41 | + expect(body).toContain('| 📦 NPM Packages | 1 |') |
| 42 | + expect(body).toContain('| **Total** | **1** |') |
| 43 | + |
| 44 | + // Should include the detailed package table (missing in original issue) |
| 45 | + expect(body).toContain('## 📦 npm Dependencies') |
| 46 | + expect(body).toContain('*1 package will be updated*') |
| 47 | + expect(body).toContain('| Package | Change | Age | Adoption | Passing | Confidence |') |
| 48 | + |
| 49 | + // Should include package details |
| 50 | + expect(body).toContain('stripe') |
| 51 | + expect(body).toContain('17.7.0') |
| 52 | + expect(body).toContain('18.4.0') |
| 53 | + |
| 54 | + // Should include badges and links like Renovate |
| 55 | + expect(body).toContain('renovatebot.com/diffs/npm/stripe') |
| 56 | + expect(body).toContain('developer.mend.io/api/mc/badges') |
| 57 | + |
| 58 | + // Should have proper structure (not just empty Release Notes) |
| 59 | + expect(body).toContain('### Release Notes') |
| 60 | + expect(body).toContain('### Configuration') |
| 61 | + |
| 62 | + // Verify it's not the broken minimal version |
| 63 | + expect(body).not.toMatch(/^This PR contains the following updates:\s*## 📦 Package Updates Summary\s*\| Type \| Count \|\s*\|------\|-------\|\s*\| \*\*Total\*\* \| \*\*1\*\* \|\s*---\s*### Release Notes\s*---/) |
| 64 | + }) |
| 65 | + |
| 66 | + it('should match Renovate-style format for major updates', async () => { |
| 67 | + const majorStripeUpdate: UpdateGroup = { |
| 68 | + name: 'Major Update - stripe', |
| 69 | + updateType: 'major', |
| 70 | + title: 'chore(deps): update dependency stripe to 18.4.0', |
| 71 | + body: '', |
| 72 | + updates: [{ |
| 73 | + name: 'stripe', |
| 74 | + currentVersion: '17.7.0', |
| 75 | + newVersion: '18.4.0', |
| 76 | + updateType: 'major', |
| 77 | + dependencyType: 'dependencies', |
| 78 | + file: 'package.json', |
| 79 | + metadata: undefined, |
| 80 | + }], |
| 81 | + } |
| 82 | + |
| 83 | + const body = await generator.generateBody(majorStripeUpdate) |
| 84 | + |
| 85 | + // The format should be similar to Renovate's table: |
| 86 | + // | Package | Change | Age | Adoption | Passing | Confidence | |
| 87 | + // |---|---|---|---|---|---| |
| 88 | + // | [stripe](https://redirect.github.com/stripe/stripe-node) | [`^17.7.0` -> `^18.4.0`](https://renovatebot.com/diffs/npm/stripe/17.7.0/18.4.0) | badges... | |
| 89 | + |
| 90 | + // Check for Renovate-style package table |
| 91 | + const tableRegex = /\| Package \| Change \| Age \| Adoption \| Passing \| Confidence \|[\s\S]*?\| \[stripe\][^|]*\| [^|]*17\.7\.0[^|]*18\.4\.0[^|]*\|/ |
| 92 | + expect(body).toMatch(tableRegex) |
| 93 | + |
| 94 | + // Should have package link |
| 95 | + expect(body).toMatch(/\[stripe\]\([^)]*github\.com[^)]*\)/) |
| 96 | + |
| 97 | + // Should have diff link |
| 98 | + expect(body).toMatch(/\[.*17\.7\.0.*18\.4\.0.*\]\([^)]*renovatebot\.com[^)]*\)/) |
| 99 | + |
| 100 | + // Should have badges |
| 101 | + expect(body).toMatch(/!\[age\]\([^)]*developer\.mend\.io[^)]*\)/) |
| 102 | + expect(body).toMatch(/!\[adoption\]\([^)]*developer\.mend\.io[^)]*\)/) |
| 103 | + expect(body).toMatch(/!\[passing\]\([^)]*developer\.mend\.io[^)]*\)/) |
| 104 | + expect(body).toMatch(/!\[confidence\]\([^)]*developer\.mend\.io[^)]*\)/) |
| 105 | + }) |
| 106 | + |
| 107 | + it('should work for different major update types', async () => { |
| 108 | + // Test composer major update |
| 109 | + const majorComposerUpdate: UpdateGroup = { |
| 110 | + name: 'Major Update - laravel/framework', |
| 111 | + updateType: 'major', |
| 112 | + title: 'chore(deps): update dependency laravel/framework to v11.0.0', |
| 113 | + body: '', |
| 114 | + updates: [{ |
| 115 | + name: 'laravel/framework', |
| 116 | + currentVersion: '10.48.0', |
| 117 | + newVersion: '11.0.0', |
| 118 | + updateType: 'major', |
| 119 | + dependencyType: 'require', |
| 120 | + file: 'composer.json', |
| 121 | + metadata: undefined, |
| 122 | + }], |
| 123 | + } |
| 124 | + |
| 125 | + const composerBody = await generator.generateBody(majorComposerUpdate) |
| 126 | + |
| 127 | + expect(composerBody).toContain('| 🎼 Composer Packages | 1 |') |
| 128 | + expect(composerBody).toContain('## 🎼 PHP/Composer Dependencies') |
| 129 | + expect(composerBody).toContain('*1 package will be updated*') |
| 130 | + expect(composerBody).toContain('laravel/framework') |
| 131 | + |
| 132 | + // Test GitHub Action major update |
| 133 | + const majorActionUpdate: UpdateGroup = { |
| 134 | + name: 'Major Update - actions/checkout', |
| 135 | + updateType: 'major', |
| 136 | + title: 'chore(deps): update dependency actions/checkout to v5', |
| 137 | + body: '', |
| 138 | + updates: [{ |
| 139 | + name: 'actions/checkout', |
| 140 | + currentVersion: 'v4', |
| 141 | + newVersion: 'v5', |
| 142 | + updateType: 'major', |
| 143 | + dependencyType: 'github-actions', |
| 144 | + file: '.github/workflows/ci.yml', |
| 145 | + metadata: undefined, |
| 146 | + }], |
| 147 | + } |
| 148 | + |
| 149 | + const actionBody = await generator.generateBody(majorActionUpdate) |
| 150 | + |
| 151 | + expect(actionBody).toContain('| 🚀 GitHub Actions | 1 |') |
| 152 | + expect(actionBody).toContain('## 🚀 GitHub Actions') |
| 153 | + expect(actionBody).toContain('*1 action will be updated*') |
| 154 | + expect(actionBody).toContain('actions/checkout') |
| 155 | + }) |
| 156 | + }) |
| 157 | +}) |
0 commit comments