Commit 9aeeb6c

Anton Golub <antongolub@antongolub.com>
2023-10-12 19:08:58
test: fix broken tests
1 parent 6f8cef4
test/stars.test.ts
@@ -7,7 +7,7 @@ import { Data } from '../src/collect/collect.js'
 describe('stars', () => {
   it('counts and renders as expected', () => {
     const badges: Badge[] = []
-    const grant = badgeCollection(badges, starsPresenter, true)
+    const grant = badgeCollection(badges)
     const data: Data = {
       user: {} as Data['user'],
       pulls: {} as Data['pulls'],
@@ -34,52 +34,53 @@ describe('stars', () => {
 
     assert.deepEqual(badges, [
       {
-        id: 'stars-2000',
-        desc: 'I collected 2000 stars.',
+        id: 'stars-100',
+        tier: 1,
+        desc: 'I collected 100 stars.',
         body:
           'Repos:\n' +
-          '* <a href="https://github.com/foo/qux     <i>2000</i></a>\n' +
-          '* <a href="https://github.com/foo/bar     <i>1000</i></a>\n' +
+          '\n' +
+          '* <a href="https://github.com/foo/bar">foo/bar: ★1000</a>\n' +
           '\n' +
           "<sup>I have push, maintainer or admin permissions, so I'm definitely an author.<sup>\n",
-        image:
-          'https://github.com/my-badges/my-badges/blob/master/src/all-badges/stars/stars-2000.png?raw=true',
+        image: '',
       },
       {
-        id: 'stars-1000',
-        desc: 'I collected 1000 stars.',
+        id: 'stars-500',
+        tier: 2,
+        desc: 'I collected 500 stars.',
         body:
           'Repos:\n' +
-          '* <a href="https://github.com/foo/qux     <i>2000</i></a>\n' +
-          '* <a href="https://github.com/foo/bar     <i>1000</i></a>\n' +
+          '\n' +
+          '* <a href="https://github.com/foo/bar">foo/bar: ★1000</a>\n' +
           '\n' +
           "<sup>I have push, maintainer or admin permissions, so I'm definitely an author.<sup>\n",
-        image:
-          'https://github.com/my-badges/my-badges/blob/master/src/all-badges/stars/stars-1000.png?raw=true',
+        image: '',
       },
       {
-        id: 'stars-500',
-        desc: 'I collected 500 stars.',
+        id: 'stars-1000',
+        tier: 3,
+        desc: 'I collected 1000 stars.',
         body:
           'Repos:\n' +
-          '* <a href="https://github.com/foo/qux     <i>2000</i></a>\n' +
-          '* <a href="https://github.com/foo/bar     <i>1000</i></a>\n' +
+          '\n' +
+          '* <a href="https://github.com/foo/bar">foo/bar: ★1000</a>\n' +
           '\n' +
           "<sup>I have push, maintainer or admin permissions, so I'm definitely an author.<sup>\n",
-        image:
-          'https://github.com/my-badges/my-badges/blob/master/src/all-badges/stars/stars-500.png?raw=true',
+        image: '',
       },
       {
-        id: 'stars-100',
-        desc: 'I collected 100 stars.',
+        id: 'stars-2000',
+        tier: 4,
+        desc: 'I collected 2000 stars.',
         body:
           'Repos:\n' +
-          '* <a href="https://github.com/foo/qux     <i>2000</i></a>\n' +
-          '* <a href="https://github.com/foo/bar     <i>1000</i></a>\n' +
+          '\n' +
+          '* <a href="https://github.com/foo/bar">foo/bar: ★1000</a>\n' +
+          '* <a href="https://github.com/foo/qux">foo/qux: ★2000</a>\n' +
           '\n' +
           "<sup>I have push, maintainer or admin permissions, so I'm definitely an author.<sup>\n",
-        image:
-          'https://github.com/my-badges/my-badges/blob/master/src/all-badges/stars/stars-100.png?raw=true',
+        image: '',
       },
     ])
   })
test/update-readme.test.ts
@@ -12,51 +12,24 @@ describe('generateReadme()', () => {
 <!-- my-badges end -->
 `
     const badges: Badge[] = []
-    const presenter = abcPresenter
-    const grant = badgeCollection(badges, presenter, false)
+    const grant = badgeCollection(badges)
 
     abcPresenter.badges.forEach((badge) => grant(badge, 'test'))
     assert.equal(badges.length, 6)
 
-    const contents1 = generateReadme(readme, badges, 64)
+    const contents = generateReadme(readme, badges, 64)
     assert.equal(
-      contents1,
+      contents,
       `
 <!-- my-badges start -->
 <h4><a href="https://github.com/my-badges/my-badges">My Badges</a></h4>
 
-<a href="my-badges/abcdef-commit.md"><img src="https://github.com/my-badges/my-badges/blob/master/src/all-badges/abc-commit/abcdef-commit.png?raw=true" alt="test" title="test" width="64"></a>
-<!-- my-badges end -->
-
-`,
-    )
-  })
-
-  it('compact', () => {
-    const readme = `
-<!-- my-badges start -->
-<!-- my-badges end -->
-`
-    const badges: Badge[] = []
-    const presenter = abcPresenter
-    const grant = badgeCollection(badges, presenter, true)
-
-    abcPresenter.badges.forEach((badge) => grant(badge, 'test'))
-    assert.equal(badges.length, 6)
-
-    const contents2 = generateReadme(readme, badges, 64)
-    assert.equal(
-      contents2,
-      `
-<!-- my-badges start -->
-<h4><a href="https://github.com/my-badges/my-badges">My Badges</a></h4>
-
-<a href="my-badges/a-commit.md"><img src="https://github.com/my-badges/my-badges/blob/master/src/all-badges/abc-commit/a-commit.png?raw=true" alt="test" title="test" width="64"></a>
-<a href="my-badges/ab-commit.md"><img src="https://github.com/my-badges/my-badges/blob/master/src/all-badges/abc-commit/ab-commit.png?raw=true" alt="test" title="test" width="64"></a>
-<a href="my-badges/abc-commit.md"><img src="https://github.com/my-badges/my-badges/blob/master/src/all-badges/abc-commit/abc-commit.png?raw=true" alt="test" title="test" width="64"></a>
-<a href="my-badges/abcd-commit.md"><img src="https://github.com/my-badges/my-badges/blob/master/src/all-badges/abc-commit/abcd-commit.png?raw=true" alt="test" title="test" width="64"></a>
-<a href="my-badges/abcde-commit.md"><img src="https://github.com/my-badges/my-badges/blob/master/src/all-badges/abc-commit/abcde-commit.png?raw=true" alt="test" title="test" width="64"></a>
-<a href="my-badges/abcdef-commit.md"><img src="https://github.com/my-badges/my-badges/blob/master/src/all-badges/abc-commit/abcdef-commit.png?raw=true" alt="test" title="test" width="64"></a>
+<a href="my-badges/a-commit.md"><img src="" alt="test" title="test" width="64"></a>
+<a href="my-badges/ab-commit.md"><img src="" alt="test" title="test" width="64"></a>
+<a href="my-badges/abc-commit.md"><img src="" alt="test" title="test" width="64"></a>
+<a href="my-badges/abcd-commit.md"><img src="" alt="test" title="test" width="64"></a>
+<a href="my-badges/abcde-commit.md"><img src="" alt="test" title="test" width="64"></a>
+<a href="my-badges/abcdef-commit.md"><img src="" alt="test" title="test" width="64"></a>
 <!-- my-badges end -->
 
 `,
README.md
@@ -120,17 +120,17 @@ jobs:
 - Start **my-badges** workflow, or wait for it to run automatically.
 
 ## Configuration
-| Param    | ENV alias      | Description                                                                                                                                             | Default       |
-|----------|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|
-| `token`  | `GITHUB_TOKEN` | Auth token                                                                                                                                              |               |
-| `user`   | `GITHUB_USER`  | Username                                                                                                                                                |               |
-| `repo`   | `GITHUB_REPO`  | Repository name to push badges                                                                                                                          | `{user/user}` |
-| `data`   |                | Path to JSON to generate badges. If empty, required data will be obtained from the GH API                                                               |               |
-| `size`   |                | Badge size for README.md, px                                                                                                                            | 64            |
-| `dryrun` |                | Generate badges, but skip pushing to git                                                                                                                |               |
-| `pick`   |                | List of badges to pick. Pass `--pick="a-commit,ab-commit,revert-revert-commit"` to generate only the specified entries. If empty gets all of them       |               |
-| `omit`   |                | List of badges to exclude. For example, if you're too shy to flex your stars: `--omit:stars-100,stars-500,stars-1000`                                   |               |
-| `tiers`  |                | Represent the highest tier badges in README.md. For example, If you have both `stars-100` and `stars-500` achievements, only the last one will be shown |               |
+| Param     | ENV alias      | Description                                                                                                                                             | Default       |
+|-----------|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|
+| `token`   | `GITHUB_TOKEN` | Auth token                                                                                                                                              |               |
+| `user`    | `GITHUB_USER`  | Username                                                                                                                                                |               |
+| `repo`    | `GITHUB_REPO`  | Repository name to push badges                                                                                                                          | `{user/user}` |
+| `data`    |                | Path to JSON to generate badges. If empty, required data will be obtained from the GH API                                                               |               |
+| `size`    |                | Badge size for README.md, px                                                                                                                            | 64            |
+| `dryrun`  |                | Generate badges, but skip pushing to git                                                                                                                |               |
+| `pick`    |                | List of badges to pick. Pass `--pick="a-commit,ab-commit,revert-revert-commit"` to generate only the specified entries. If empty gets all of them       |               |
+| `omit`    |                | List of badges to exclude. For example, if you're too shy to flex your stars: `--omit:stars-100,stars-500,stars-1000`                                   |               |
+| `compact` |                | Represent the highest tier badges in README.md. For example, If you have both `stars-100` and `stars-500` achievements, only the last one will be shown |               |
 
 ## Contributing badges