master
1import { describe, test, expect } from 'vitest'
2import starsPresenter from './stars.js'
3import { badgeCollection } from '../../src/present-badges.js'
4import { Data } from '../../src/data.js'
5import { Badge } from '../../src/badges.js'
6
7describe('stars', () => {
8 test('counts and renders as expected', () => {
9 const badges: Badge[] = []
10 const grant = badgeCollection(badges)
11 const data: Data = {
12 user: {} as Data['user'],
13 pulls: [] as Data['pulls'],
14 issues: {} as Data['issues'],
15 repos: [
16 {
17 stargazers: {
18 totalCount: 1000,
19 },
20 name: 'bar',
21 owner: {
22 login: 'foo',
23 },
24 commits: [],
25 },
26 {
27 stargazers: {
28 totalCount: 2000,
29 },
30 name: 'qux',
31 owner: {
32 login: 'foo',
33 },
34 commits: [] as any[],
35 },
36 ] as Data['repos'],
37 } as Data
38
39 starsPresenter.present(data, grant)
40
41 expect(badges).toEqual([
42 {
43 id: 'stars-100',
44 tier: 1,
45 desc: 'I collected 100 stars.',
46 body:
47 'Repos:\n' +
48 '\n' +
49 '* <a href="https://github.com/foo/bar">foo/bar: ★1000</a>\n' +
50 '\n' +
51 "<sup>I have push, maintainer or admin permissions, so I'm definitely an author.<sup>\n",
52 image: '',
53 },
54 {
55 id: 'stars-500',
56 tier: 2,
57 desc: 'I collected 500 stars.',
58 body:
59 'Repos:\n' +
60 '\n' +
61 '* <a href="https://github.com/foo/bar">foo/bar: ★1000</a>\n' +
62 '\n' +
63 "<sup>I have push, maintainer or admin permissions, so I'm definitely an author.<sup>\n",
64 image: '',
65 },
66 {
67 id: 'stars-1000',
68 tier: 3,
69 desc: 'I collected 1000 stars.',
70 body:
71 'Repos:\n' +
72 '\n' +
73 '* <a href="https://github.com/foo/bar">foo/bar: ★1000</a>\n' +
74 '\n' +
75 "<sup>I have push, maintainer or admin permissions, so I'm definitely an author.<sup>\n",
76 image: '',
77 },
78 {
79 id: 'stars-2000',
80 tier: 4,
81 desc: 'I collected 2000 stars.',
82 body:
83 'Repos:\n' +
84 '\n' +
85 '* <a href="https://github.com/foo/qux">foo/qux: ★2000</a>\n' +
86 '* <a href="https://github.com/foo/bar">foo/bar: ★1000</a>\n' +
87 '\n' +
88 "<sup>I have push, maintainer or admin permissions, so I'm definitely an author.<sup>\n",
89 image: '',
90 },
91 ])
92 })
93})