Skip to content

Commit d2d1fd0

Browse files
committed
Fix tests
1 parent ddddec8 commit d2d1fd0

109 files changed

Lines changed: 615 additions & 499 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/commands/analytics/cmd-analytics.mts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ async function run(
9898

9999
const { file, json, markdown } = cli.flags
100100

101-
const hasApiToken = hasDefaultToken()
101+
const dryRun = !!cli.flags['dryRun']
102102

103103
const noLegacy =
104104
!cli.flags['scope'] && !cli.flags['repo'] && !cli.flags['time']
105105

106+
const hasApiToken = hasDefaultToken()
107+
106108
const outputKind = getOutputKind(json, markdown)
107109

108110
const wasValidInput = checkCommandInput(
@@ -149,16 +151,15 @@ async function run(
149151
{
150152
nook: true,
151153
test: hasApiToken,
152-
message:
153-
'You need to be logged in to use this command. See `socket login`.',
154-
fail: 'missing Socket API token',
154+
message: 'This command requires a Socket API token for access',
155+
fail: 'try `socket login`',
155156
},
156157
)
157158
if (!wasValidInput) {
158159
return
159160
}
160161

161-
if (cli.flags['dryRun']) {
162+
if (dryRun) {
162163
logger.log(DRY_RUN_BAILING_NOW)
163164
return
164165
}

src/commands/analytics/cmd-analytics.test.mts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('socket analytics', async () => {
7878
\\xd7 Input error: Please review the input requirements and try again
7979
8080
\\u221a The time filter must either be 7, 30 or 90
81-
\\xd7 You need to be logged in to use this command. See \`socket login\`. (missing Socket API token)"
81+
\\xd7 This command requires a Socket API token for access (try \`socket login\`)"
8282
`)
8383

8484
expect(code, 'dry-run should exit with code 2 if missing input').toBe(2)
@@ -94,7 +94,7 @@ describe('socket analytics', async () => {
9494
'bar',
9595
'--dry-run',
9696
'--config',
97-
'{"apiToken":"anything"}',
97+
'{"apiToken":"fakeToken"}',
9898
],
9999
'should reject legacy flags',
100100
async cmd => {
@@ -118,7 +118,7 @@ describe('socket analytics', async () => {
118118
)
119119

120120
cmdit(
121-
['analytics', '--dry-run', '--config', '{"apiToken":"anything"}'],
121+
['analytics', '--dry-run', '--config', '{"apiToken":"fakeToken"}'],
122122
'should run to dryrun without args',
123123
async cmd => {
124124
const { code, stderr, stdout } = await invokeNpm(binCliPath, cmd)
@@ -136,7 +136,7 @@ describe('socket analytics', async () => {
136136
)
137137

138138
cmdit(
139-
['analytics', 'org', '--dry-run', '--config', '{"apiToken":"anything"}'],
139+
['analytics', 'org', '--dry-run', '--config', '{"apiToken":"fakeToken"}'],
140140
'should accept org arg',
141141
async cmd => {
142142
const { code, stderr, stdout } = await invokeNpm(binCliPath, cmd)
@@ -154,7 +154,7 @@ describe('socket analytics', async () => {
154154
)
155155

156156
cmdit(
157-
['analytics', 'repo', '--dry-run', '--config', '{"apiToken":"anything"}'],
157+
['analytics', 'repo', '--dry-run', '--config', '{"apiToken":"fakeToken"}'],
158158
'should ask for repo name with repo arg',
159159
async cmd => {
160160
const { code, stderr, stdout } = await invokeNpm(binCliPath, cmd)
@@ -183,7 +183,7 @@ describe('socket analytics', async () => {
183183
'daname',
184184
'--dry-run',
185185
'--config',
186-
'{"apiToken":"anything"}',
186+
'{"apiToken":"fakeToken"}',
187187
],
188188
'should accept repo with arg',
189189
async cmd => {
@@ -202,7 +202,7 @@ describe('socket analytics', async () => {
202202
)
203203

204204
cmdit(
205-
['analytics', '7', '--dry-run', '--config', '{"apiToken":"anything"}'],
205+
['analytics', '7', '--dry-run', '--config', '{"apiToken":"fakeToken"}'],
206206
'should accept time 7 arg',
207207
async cmd => {
208208
const { code, stderr, stdout } = await invokeNpm(binCliPath, cmd)
@@ -220,7 +220,7 @@ describe('socket analytics', async () => {
220220
)
221221

222222
cmdit(
223-
['analytics', '30', '--dry-run', '--config', '{"apiToken":"anything"}'],
223+
['analytics', '30', '--dry-run', '--config', '{"apiToken":"fakeToken"}'],
224224
'should accept time 30 arg',
225225
async cmd => {
226226
const { code, stderr, stdout } = await invokeNpm(binCliPath, cmd)
@@ -238,7 +238,7 @@ describe('socket analytics', async () => {
238238
)
239239

240240
cmdit(
241-
['analytics', '90', '--dry-run', '--config', '{"apiToken":"anything"}'],
241+
['analytics', '90', '--dry-run', '--config', '{"apiToken":"fakeToken"}'],
242242
'should accept time 90 arg',
243243
async cmd => {
244244
const { code, stderr, stdout } = await invokeNpm(binCliPath, cmd)
@@ -263,7 +263,7 @@ describe('socket analytics', async () => {
263263
'7',
264264
'--dry-run',
265265
'--config',
266-
'{"apiToken":"anything"}',
266+
'{"apiToken":"fakeToken"}',
267267
],
268268
'should report legacy flag',
269269
async cmd => {
@@ -293,7 +293,7 @@ describe('socket analytics', async () => {
293293
'7',
294294
'--dry-run',
295295
'--config',
296-
'{"apiToken":"anything"}',
296+
'{"apiToken":"fakeToken"}',
297297
],
298298
'should accept org and time arg',
299299
async cmd => {
@@ -319,7 +319,7 @@ describe('socket analytics', async () => {
319319
'30',
320320
'--dry-run',
321321
'--config',
322-
'{"apiToken":"anything"}',
322+
'{"apiToken":"fakeToken"}',
323323
],
324324
'should accept repo and time arg',
325325
async cmd => {

src/commands/audit-log/cmd-audit-log.mts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,22 @@ async function run(
9292
parentName,
9393
})
9494

95-
const {
96-
dryRun,
97-
interactive,
98-
json,
99-
markdown,
100-
org: orgFlag,
101-
page,
102-
perPage,
103-
} = cli.flags
95+
const { interactive, json, markdown, org: orgFlag, page, perPage } = cli.flags
96+
97+
const dryRun = !!cli.flags['dryRun']
98+
99+
const noLegacy = !cli.flags['type']
104100

105101
let [typeFilter = ''] = cli.input
102+
106103
typeFilter = String(typeFilter)
107104

108105
const hasApiToken = hasDefaultToken()
109106

110-
const noLegacy = !cli.flags['type']
111-
112107
const [orgSlug] = await determineOrgSlug(
113108
String(orgFlag || ''),
114109
!!interactive,
115-
!!dryRun,
110+
dryRun,
116111
)
117112

118113
const outputKind = getOutputKind(json, markdown)
@@ -134,9 +129,8 @@ async function run(
134129
{
135130
nook: true,
136131
test: hasApiToken,
137-
message:
138-
'You need to be logged in to use this command. See `socket login`.',
139-
fail: 'missing Socket API token',
132+
message: 'This command requires a Socket API token for access',
133+
fail: 'try `socket login`',
140134
},
141135
{
142136
nook: true,
@@ -156,7 +150,7 @@ async function run(
156150
return
157151
}
158152

159-
if (cli.flags['dryRun']) {
153+
if (dryRun) {
160154
logger.log(DRY_RUN_BAILING_NOW)
161155
return
162156
}

src/commands/audit-log/cmd-audit-log.test.mts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('socket audit-log', async () => {
6767
)
6868

6969
cmdit(
70-
['audit-log', '--dry-run', '--config', '{"apiToken":"anything"}'],
70+
['audit-log', '--dry-run', '--config', '{"apiToken":"fakeToken"}'],
7171
'should report missing org name',
7272
async cmd => {
7373
const { code, stderr, stdout } = await invokeNpm(binCliPath, cmd)
@@ -80,7 +80,8 @@ describe('socket audit-log', async () => {
8080
|_____|___|___|_,_|___|_|.dev | Command: \`socket audit-log\`, cwd: <redacted>
8181
8282
\\u203c Unable to determine the target org. Trying to auto-discover it now...
83-
i Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag.
83+
i Note: Run \`socket login\` to set a default org.
84+
Use the --org flag to override the default org.
8485
8586
\\xd7 Skipping auto-discovery of org in dry-run mode
8687
\\xd7 Input error: Please review the input requirements and try again
@@ -99,7 +100,7 @@ describe('socket audit-log', async () => {
99100
'xyz',
100101
'--dry-run',
101102
'--config',
102-
'{"apiToken":"anything", "defaultOrg": "fakeorg"}',
103+
'{"apiToken":"fakeToken", "defaultOrg": "fakeOrg"}',
103104
],
104105
'should report legacy flag',
105106
async cmd => {
@@ -126,7 +127,7 @@ describe('socket audit-log', async () => {
126127
'audit-log',
127128
'--dry-run',
128129
'--config',
129-
'{"apiToken":"anything", "defaultOrg": "fakeorg"}',
130+
'{"apiToken":"fakeToken", "defaultOrg": "fakeOrg"}',
130131
],
131132
'should accept default org',
132133
async cmd => {
@@ -151,7 +152,7 @@ describe('socket audit-log', async () => {
151152
'forcedorg',
152153
'--dry-run',
153154
'--config',
154-
'{"apiToken":"anything"}',
155+
'{"apiToken":"fakeToken"}',
155156
],
156157
'should accept --org flag in v1',
157158
async cmd => {

src/commands/ci/cmd-ci.mts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ async function run(
6565
parentName,
6666
})
6767

68-
if (cli.flags['dryRun']) {
68+
const dryRun = !!cli.flags['dryRun']
69+
70+
if (dryRun) {
6971
logger.log(DRY_RUN_BAILING_NOW)
7072
return
7173
}

src/commands/ci/cmd-ci.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('socket ci', async () => {
5151
)
5252

5353
cmdit(
54-
['ci', '--dry-run', '--config', '{"apiToken":"anything"}'],
54+
['ci', '--dry-run', '--config', '{"apiToken":"fakeToken"}'],
5555
'should require args with just dry-run',
5656
async cmd => {
5757
const { code, stderr, stdout } = await invokeNpm(binCliPath, cmd)

src/commands/cli.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('socket root command', async () => {
101101
})
102102

103103
cmdit(
104-
['mootools', '--dry-run', '--config', '{"apiToken":"anything"}'],
104+
['mootools', '--dry-run', '--config', '{"apiToken":"fakeToken"}'],
105105
'should require args with just dry-run',
106106
async cmd => {
107107
const { code, stderr, stdout } = await invokeNpm(binCliPath, cmd)

src/commands/config/cmd-config-auto.mts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ ${getSupportedConfigEntries()
6868

6969
const { json, markdown } = cli.flags
7070

71+
const dryRun = !!cli.flags['dryRun']
72+
7173
const [key = ''] = cli.input
7274

7375
const outputKind = getOutputKind(json, markdown)
@@ -91,7 +93,7 @@ ${getSupportedConfigEntries()
9193
return
9294
}
9395

94-
if (cli.flags['dryRun']) {
96+
if (dryRun) {
9597
logger.log(DRY_RUN_BAILING_NOW)
9698
return
9799
}

src/commands/config/cmd-config-auto.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('socket config auto', async () => {
6060
'defaultOrg',
6161
'--dry-run',
6262
'--config',
63-
'{"apiToken":"anything"}',
63+
'{"apiToken":"fakeToken"}',
6464
],
6565
'should require args with just dry-run',
6666
async cmd => {

src/commands/config/cmd-config-get.mts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ async function run(
6666

6767
const { json, markdown } = cli.flags
6868

69+
const dryRun = !!cli.flags['dryRun']
70+
6971
const [key = ''] = cli.input
7072

7173
const outputKind = getOutputKind(json, markdown)
@@ -89,7 +91,7 @@ async function run(
8991
return
9092
}
9193

92-
if (cli.flags['dryRun']) {
94+
if (dryRun) {
9395
logger.log(DRY_RUN_BAILING_NOW)
9496
return
9597
}

0 commit comments

Comments
 (0)