1
1
import { expect } from 'chai'
2
2
import { readFileSync } from 'fs'
3
- import { validateExportStream } from '../src/verify'
3
+ import { validateExportStream } from '../dist'
4
+ import { Readable } from 'stream'
4
5
5
6
describe ( 'validateExportStream' , ( ) => {
6
7
it ( 'should validate a valid tarball' , async ( ) => {
7
8
// Load a valid tarball (e.g., exported-profile-valid.tar)
8
9
const tarBuffer = readFileSync (
9
10
'test/fixtures/tarball-samples/valid-export.tar'
10
11
)
11
- const result = await validateExportStream ( tarBuffer )
12
+ const tarStream = Readable . from ( tarBuffer )
13
+ const result = await validateExportStream ( tarStream )
14
+ console . log ( '🚀 ~ it ~ valid result:' , result )
12
15
13
16
expect ( result . valid ) . to . be . true
14
17
expect ( result . errors ) . to . be . an ( 'array' ) . that . is . empty
@@ -19,7 +22,9 @@ describe('validateExportStream', () => {
19
22
const tarBuffer = readFileSync (
20
23
'test/fixtures/tarball-samples/missing-manifest.tar'
21
24
)
22
- const result = await validateExportStream ( tarBuffer )
25
+ const tarStream = Readable . from ( tarBuffer )
26
+ const result = await validateExportStream ( tarStream )
27
+ console . log ( '🚀 ~ it ~ miss mani result:' , result )
23
28
24
29
expect ( result . valid ) . to . be . false
25
30
} )
@@ -29,48 +34,43 @@ describe('validateExportStream', () => {
29
34
const tarBuffer = readFileSync (
30
35
'test/fixtures/tarball-samples/missing-actor.tar'
31
36
)
32
- const result = await validateExportStream ( tarBuffer )
37
+ const tarStream = Readable . from ( tarBuffer )
38
+ const result = await validateExportStream ( tarStream )
33
39
34
40
expect ( result . valid ) . to . be . false
35
41
console . log ( JSON . stringify ( result . errors ) )
36
42
} )
37
43
38
- // it('should fail if outbox.json is missing', async () => {
39
- // // Load a tarball with missing outbox.json
40
- // const tarBuffer = readFileSync(
41
- // 'test/fixtures/exported-profile-missing-outbox.tar'
42
- // )
43
- // const result = await validateExportStream(tarBuffer)
44
+ it ( 'should fail if outbox.json is missing' , async ( ) => {
45
+ // Load a tarball with missing outbox.json
46
+ const tarBuffer = readFileSync (
47
+ 'test/fixtures/tarball-samples/missing-outbox.tar'
48
+ )
49
+ const tarStream = Readable . from ( tarBuffer )
50
+ const result = await validateExportStream ( tarStream )
44
51
45
- // expect(result.valid).to.be.false
46
- // expect(result.errors).to.include(
47
- // 'Missing required file: activitypub/outbox.json'
48
- // )
49
- // })
52
+ expect ( result . valid ) . to . be . false
53
+ } )
50
54
51
- // it('should fail if actor.json contains invalid JSON', async () => {
52
- // // Load a tarball with invalid JSON in actor.json
53
- // const tarBuffer = readFileSync(
54
- // 'test/fixtures/exported-profile-invalid-actor-json.tar'
55
- // )
56
- // const result = await validateExportStream(tarBuffer)
55
+ it ( 'should fail if actor.json contains invalid JSON' , async ( ) => {
56
+ // Load a tarball with invalid JSON in actor.json
57
+ const tarBuffer = readFileSync (
58
+ 'test/fixtures/tarball-samples/invalid-actor.tar'
59
+ )
60
+ const tarStream = Readable . from ( tarBuffer )
61
+ const result = await validateExportStream ( tarStream )
57
62
58
- // expect(result.valid).to.be.false
59
- // expect(result.errors).to.include(
60
- // 'Error processing file activitypub/actor.json: Unexpected token } in JSON at position 42'
61
- // )
62
- // })
63
+ expect ( result . valid ) . to . be . false
64
+ } )
63
65
64
- // it('should fail if manifest.yaml is invalid', async () => {
65
- // // Load a tarball with invalid manifest.yaml
66
- // const tarBuffer = readFileSync(
67
- // 'test/fixtures/exported-profile-invalid-manifest.tar'
68
- // )
69
- // const result = await validateExportStream(tarBuffer)
66
+ it ( 'should fail if manifest.yaml is invalid' , async ( ) => {
67
+ // Load a tarball with invalid manifest.yaml
68
+ const tarBuffer = readFileSync (
69
+ 'test/fixtures/tarball-samples/invalid-manifest.tar'
70
+ )
71
+ const tarStream = Readable . from ( tarBuffer )
72
+ const result = await validateExportStream ( tarStream )
70
73
71
- // expect(result.valid).to.be.false
72
- // expect(result.errors).to.include(
73
- // 'Manifest is missing required field: ubc-version'
74
- // )
75
- // })
74
+ expect ( result . valid ) . to . be . false
75
+ } )
76
76
} )
0 commit comments