Skip to content

Commit f52bbc9

Browse files
authored
feat: display manifest root metadata (#643)
* feat: display manifest root metadata * test: adjust tests * test: add test for root metadata * test: improve assertions * test(fix): add verbose flag * test: swap order of documents
1 parent 06ae618 commit f52bbc9

File tree

2 files changed

+63
-23
lines changed

2 files changed

+63
-23
lines changed

src/command/manifest/list.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import chalk from 'chalk'
33
import { Argument, LeafCommand, Option } from 'furious-commander'
44
import { exit } from 'process'
55
import { makeBzzAddress } from '../../utils/bzz-address'
6+
import { createKeyValue } from '../../utils/text'
67
import { RootCommand } from '../root-command'
78

89
export class List extends RootCommand implements LeafCommand {
@@ -34,6 +35,22 @@ export class List extends RootCommand implements LeafCommand {
3435
exit(1)
3536
}
3637

38+
if (this.verbose) {
39+
this.console.log(chalk.green.bold('Root (/) metadata'))
40+
node
41+
.getRootMetadata()
42+
.ifPresent(metadata => {
43+
for (const entry of Object.entries(metadata)) {
44+
this.console.log(createKeyValue(entry[0], entry[1]))
45+
}
46+
})
47+
.ifAbsent(() => {
48+
this.console.log(chalk.dim('No metadata found'))
49+
})
50+
this.console.log('')
51+
}
52+
53+
this.console.log(chalk.green.bold('Nodes'))
3754
for (const node of nodes) {
3855
this.console.log(new Reference(node.targetAddress).toHex() + ' ' + node.fullPathString)
3956

@@ -53,6 +70,7 @@ export class List extends RootCommand implements LeafCommand {
5370
this.console.log(chalk.dim(entry[0] + ': ' + entry[1]))
5471
}
5572
}
73+
this.console.log('')
5674
}
5775
}
5876
}

test/command/manifest.spec.ts

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,24 @@ describeCommand('Test Manifest command', ({ consoleMessages, hasMessageContainin
141141
hash = await runAndGetManifest(['manifest', 'add', hash, 'src'])
142142
consoleMessages.length = 0
143143
await invokeTestCli(['manifest', 'list', `bzz://${hash}/command/pss/send.ts`])
144-
expect(consoleMessages).toHaveLength(1)
144+
expect(consoleMessages).toMatchLinesInAnyOrder([['Nodes'], ['command/pss/send.ts']])
145+
expect(consoleMessages).toHaveLength(3)
145146
})
146147

147148
it('should list folder', async () => {
148149
let hash = await runAndGetManifest(['manifest', 'create'])
149150
hash = await runAndGetManifest(['manifest', 'add', hash, 'src'])
150151
consoleMessages.length = 0
151152
await invokeTestCli(['manifest', 'list', `bzz://${hash}/command/pss`])
152-
expect(consoleMessages).toHaveLength(5)
153+
expect(consoleMessages).toMatchLinesInAnyOrder([
154+
['Nodes'],
155+
['command/pss/index.ts'],
156+
['command/pss/pss-command.ts'],
157+
['command/pss/receive.ts'],
158+
['command/pss/send.ts'],
159+
['command/pss/subscribe.ts'],
160+
])
161+
expect(consoleMessages).toHaveLength(11)
153162
})
154163

155164
it('should download single file', async () => {
@@ -241,63 +250,57 @@ describeCommand('Test Manifest command', ({ consoleMessages, hasMessageContainin
241250
const command = invocation.runnable as unknown as FeedUpload
242251
consoleMessages.length = 0
243252
await invokeTestCli(['manifest', 'list', `${command.feedManifest}`])
244-
expect(consoleMessages[0]).toContain('README.md')
253+
expect(consoleMessages).toMatchLinesInOrder([['README.md']])
245254
})
246255

247256
it('should list single file when specified partially', async () => {
248257
await invokeTestCli(['manifest', 'list', `${srcHash}/ind`])
249-
expect(consoleMessages[0]).toContain('index.txt')
258+
expect(consoleMessages).toMatchLinesInOrder([['index.txt']])
250259
})
251260

252261
it('should list single file when specified fully', async () => {
253262
await invokeTestCli(['manifest', 'list', `${srcHash}/index.txt`])
254-
expect(consoleMessages[0]).toContain('index.txt')
263+
expect(consoleMessages).toMatchLinesInOrder([['index.txt']])
255264
})
256265

257266
it('should list files in folder when specified partially', async () => {
258267
await invokeTestCli(['manifest', 'list', `${srcHash}/lev`])
259-
expect(consoleMessages[0]).toContain('level-one/level-two/1.txt')
260-
expect(consoleMessages[1]).toContain('level-one/level-two/2.txt')
268+
expect(consoleMessages).toMatchLinesInOrder([['level-one/level-two/1.txt'], ['level-one/level-two/2.txt']])
261269
})
262270

263271
it('should list files in folder when specified fully without trailing slash', async () => {
264272
await invokeTestCli(['manifest', 'list', `${srcHash}/level-one/level-two`])
265-
expect(consoleMessages[0]).toContain('level-one/level-two/1.txt')
266-
expect(consoleMessages[1]).toContain('level-one/level-two/2.txt')
273+
expect(consoleMessages).toMatchLinesInOrder([['level-one/level-two/1.txt'], ['level-one/level-two/2.txt']])
267274
})
268275

269276
it('should list files in folder when specified fully with trailing slash', async () => {
270-
await invokeTestCli(['manifest', 'list', `${srcHash}/level-one/level-two`])
271-
expect(consoleMessages[0]).toContain('level-one/level-two/1.txt')
272-
expect(consoleMessages[1]).toContain('level-one/level-two/2.txt')
277+
await invokeTestCli(['manifest', 'list', `${srcHash}/level-one/level-two/`])
278+
expect(consoleMessages).toMatchLinesInOrder([['level-one/level-two/1.txt'], ['level-one/level-two/2.txt']])
273279
})
274280

275281
it('should download single file when specified partially', async () => {
276282
await invokeTestCli(['manifest', 'download', `${srcHash}/in`, 'test/data/6'])
277-
expect(consoleMessages[0]).toContain('index.txt')
283+
expect(consoleMessages).toMatchLinesInOrder([['index.txt']])
278284
})
279285

280286
it('should download single file when specified fully', async () => {
281287
await invokeTestCli(['manifest', 'download', `${srcHash}/index.txt`, 'test/data/6'])
282-
expect(consoleMessages[0]).toContain('index.txt')
288+
expect(consoleMessages).toMatchLinesInOrder([['index.txt']])
283289
})
284290

285291
it('should download files in folder when specified partially', async () => {
286292
await invokeTestCli(['manifest', 'download', `${srcHash}/level-one/l`, 'test/data/6'])
287-
expect(consoleMessages[0]).toContain('level-one/level-two/1.txt')
288-
expect(consoleMessages[2]).toContain('level-one/level-two/2.txt')
293+
expect(consoleMessages).toMatchLinesInOrder([['level-one/level-two/1.txt'], ['level-one/level-two/2.txt']])
289294
})
290295

291296
it('should download files in folder when specified fully without trailing slash', async () => {
292297
await invokeTestCli(['manifest', 'download', `${srcHash}/level-one/level-two`, 'test/data/6'])
293-
expect(consoleMessages[0]).toContain('level-one/level-two/1.txt')
294-
expect(consoleMessages[2]).toContain('level-one/level-two/2.txt')
298+
expect(consoleMessages).toMatchLinesInOrder([['level-one/level-two/1.txt'], ['level-one/level-two/2.txt']])
295299
})
296300

297301
it('should download files in folder when specified fully with trailing slash', async () => {
298302
await invokeTestCli(['manifest', 'download', `${srcHash}/level-one/level-two/`, 'test/data/6'])
299-
expect(consoleMessages[0]).toContain('level-one/level-two/1.txt')
300-
expect(consoleMessages[2]).toContain('level-one/level-two/2.txt')
303+
expect(consoleMessages).toMatchLinesInOrder([['level-one/level-two/1.txt'], ['level-one/level-two/2.txt']])
301304
})
302305

303306
it('should handle error for invalid download hash', async () => {
@@ -341,8 +344,27 @@ describeCommand('Test Manifest command', ({ consoleMessages, hasMessageContainin
341344
const hash = (invocation.runnable as Upload).result.getOrThrow()
342345
consoleMessages.length = 0
343346
await invokeTestCli(['manifest', 'download', hash.toHex()])
344-
expect(consoleMessages[0]).toContain('images/swarm.png')
345-
expect(consoleMessages[2]).toContain('index.html')
346-
expect(consoleMessages[4]).toContain('swarm.bzz')
347+
expect(consoleMessages).toMatchLinesInOrder([['images/swarm.png'], ['index.html'], ['swarm.bzz']])
348+
})
349+
350+
it('should show root manifest metadata', async () => {
351+
const invocation = await invokeTestCli([
352+
'upload',
353+
'docs',
354+
...getStampOption(),
355+
'--index-document',
356+
'index.txt',
357+
'--error-document',
358+
'error.txt',
359+
])
360+
const hash = (invocation.runnable as Upload).result.getOrThrow()
361+
consoleMessages.length = 0
362+
await invokeTestCli(['manifest', 'list', hash.toHex(), '--verbose'])
363+
expect(consoleMessages).toMatchLinesInOrder([
364+
['Root (/) metadata'],
365+
['website-error-document: error.txt'],
366+
['website-index-document: index.txt'],
367+
['Nodes'],
368+
])
347369
})
348370
})

0 commit comments

Comments
 (0)