Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6afa20d

Browse files
committedJan 9, 2025·
Add ReadableStream support for importActorProfile and validateExportStream; update dependencies
1 parent c869227 commit 6afa20d

7 files changed

+42
-38
lines changed
 

‎out/test-export-2024-01-01.tar

0 Bytes
Binary file not shown.

‎package.json

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"./package.json": "./package.json"
3333
},
3434
"dependencies": {
35+
"eslint-plugin-n": "^17.15.1",
36+
"stream": "^0.0.3",
3537
"tar-stream": "^3.1.7",
3638
"yaml": "^2.5.1"
3739
},
10.9 KB
Binary file not shown.
Binary file not shown.
10.8 KB
Binary file not shown.

‎test/index.spec.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { exportActorProfile, importActorProfile } from '../src'
55
import { outbox } from './fixtures/outbox'
66
import { actorProfile } from './fixtures/actorProfile'
77
import { expect } from 'chai'
8+
import { Readable } from 'node:stream'
89

910
describe('exportActorProfile', () => {
1011
it('calls function', async () => {
@@ -40,7 +41,8 @@ describe('importActorProfile', () => {
4041
)
4142

4243
// Use the importActorProfile function to parse the tar contents
43-
const importedData = await importActorProfile(tarBuffer)
44+
const tarStream = Readable.from(tarBuffer)
45+
const importedData = await importActorProfile(tarStream)
4446

4547
// Log or inspect the imported data structure
4648
// console.log('Imported Data:', importedData)

‎test/verify.spec.ts

+37-37
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { expect } from 'chai'
22
import { readFileSync } from 'fs'
3-
import { validateExportStream } from '../src/verify'
3+
import { validateExportStream } from '../dist'
4+
import { Readable } from 'stream'
45

56
describe('validateExportStream', () => {
67
it('should validate a valid tarball', async () => {
78
// Load a valid tarball (e.g., exported-profile-valid.tar)
89
const tarBuffer = readFileSync(
910
'test/fixtures/tarball-samples/valid-export.tar'
1011
)
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)
1215

1316
expect(result.valid).to.be.true
1417
expect(result.errors).to.be.an('array').that.is.empty
@@ -19,7 +22,9 @@ describe('validateExportStream', () => {
1922
const tarBuffer = readFileSync(
2023
'test/fixtures/tarball-samples/missing-manifest.tar'
2124
)
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)
2328

2429
expect(result.valid).to.be.false
2530
})
@@ -29,48 +34,43 @@ describe('validateExportStream', () => {
2934
const tarBuffer = readFileSync(
3035
'test/fixtures/tarball-samples/missing-actor.tar'
3136
)
32-
const result = await validateExportStream(tarBuffer)
37+
const tarStream = Readable.from(tarBuffer)
38+
const result = await validateExportStream(tarStream)
3339

3440
expect(result.valid).to.be.false
3541
console.log(JSON.stringify(result.errors))
3642
})
3743

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)
4451

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+
})
5054

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)
5762

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+
})
6365

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)
7073

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+
})
7676
})

0 commit comments

Comments
 (0)
Please sign in to comment.