This repository was archived by the owner on Aug 7, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbase.test.js
More file actions
123 lines (106 loc) · 3.28 KB
/
Copy pathbase.test.js
File metadata and controls
123 lines (106 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* Unit tests for the GitHub API base class.
*/
import Base from '../../src/github/base.js'
describe('base', () => {
/**
* Test that Base class throws error without token.
*/
test('should throw error when no token provided', () => {
expect(() => {
new Base({})
}).toThrow('GitHub token is required')
})
/**
* Test that Base class initializes with valid token.
*/
test('should initialize with valid token', () => {
const base = new Base({
token: 'test-token',
debug: false,
})
expect(base.logger).toBeDefined()
expect(base.spinner).toBeDefined()
expect(base.octokit).toBeDefined()
})
/**
* Test that Base class handles debug mode correctly.
*/
test('should handle debug mode correctly', () => {
const base = new Base({
token: 'test-token',
debug: true,
})
expect(base.logger).toBeDefined()
expect(base.spinner).toBeDefined()
expect(base.octokit).toBeDefined()
})
/**
* Test constructor options
*/
describe('constructor options', () => {
test('should handle all constructor parameters', () => {
const options = {
token: 'test-token',
hostname: 'github.enterprise.com',
debug: true,
archived: true,
forked: true,
}
const base = new Base(options)
expect(base.archived).toBe(true)
expect(base.forked).toBe(true)
expect(base.logger).toBeDefined()
expect(base.octokit).toBeDefined()
})
test('should handle default values', () => {
const base = new Base({token: 'test-token'})
expect(base.archived).toBe(false)
expect(base.forked).toBe(false)
})
test('should handle empty options with token', () => {
const base = new Base({token: 'test-token'})
expect(base).toBeInstanceOf(Base)
expect(base.logger).toBeDefined()
expect(base.octokit).toBeDefined()
})
})
/**
* Test property getters
*/
describe('property getters', () => {
let base
beforeEach(() => {
base = new Base({
token: 'test-token',
debug: false,
})
})
test('should return logger instance', () => {
expect(base.logger).toBeDefined()
expect(typeof base.logger.info).toBe('function')
expect(typeof base.logger.error).toBe('function')
expect(typeof base.logger.warn).toBe('function')
})
test('should return spinner instance', () => {
expect(base.spinner).toBeDefined()
expect(base.spinner).toBe(base.logger) // spinner is alias for logger
})
test('should return octokit instance', () => {
expect(base.octokit).toBeDefined()
expect(typeof base.octokit.request).toBe('function')
})
test('should return archived flag', () => {
const baseWithArchived = new Base({token: 'test', archived: true})
expect(baseWithArchived.archived).toBe(true)
const baseWithoutArchived = new Base({token: 'test', archived: false})
expect(baseWithoutArchived.archived).toBe(false)
})
test('should return forked flag', () => {
const baseWithForked = new Base({token: 'test', forked: true})
expect(baseWithForked.forked).toBe(true)
const baseWithoutForked = new Base({token: 'test', forked: false})
expect(baseWithoutForked.forked).toBe(false)
})
})
})