33import * as dagPB from '@ipld/dag-pb'
44import { expect } from 'aegir/chai'
55import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
6+ import { UnixFS } from 'ipfs-unixfs'
67import { factory } from './utils/factory.js'
78import type { KuboRPCClient } from '../src/index.js'
89
@@ -19,23 +20,35 @@ describe('.add', function () {
1920
2021 after ( async function ( ) { return f . clean ( ) } )
2122
22- it ( 'should ignore metadata until https://github.com/ipfs/go-ipfs/issues/ 6920 is implemented ' , async function ( ) {
23+ it ( 'should send metadata when provided (affects CID) but not return it until issue # 6920 is resolved ' , async function ( ) {
2324 const data = uint8ArrayFromString ( 'some data' )
2425 const result = await ipfs . add ( data , {
2526 // @ts -expect-error missing field
2627 mode : 0o600 ,
2728 mtime : {
2829 secs : 1000 ,
29- nsecs : 0
30+ nsecs : 500
3031 }
3132 } )
3233
34+ // Metadata is not returned in response yet (issue #6920)
3335 expect ( result ) . to . not . have . property ( 'mode' )
3436 expect ( result ) . to . not . have . property ( 'mtime' )
3537 expect ( result ) . to . have . property ( 'cid' )
3638
3739 const { cid } = result
3840 expect ( cid ) . to . have . property ( 'code' , dagPB . code )
39- expect ( cid . toString ( ) ) . to . equal ( 'QmVv4Wz46JaZJeH5PMV4LGbRiiMKEmszPYY3g6fjGnVXBS' )
41+ // CID is different because metadata is now properly sent to the API
42+ expect ( cid . toString ( ) ) . to . equal ( 'QmPDB1sHH2FNqwJm2A6747uf6JUZyEB2cnNFRPz2uzjoDZ' )
43+
44+ // Verify metadata is stored in UnixFS structure via DAG API
45+ const dagNode = await ipfs . dag . get ( cid )
46+ const pbData = dagNode . value . Data
47+ const unixfs = UnixFS . unmarshal ( pbData )
48+
49+ // Verify mode and mtime are stored
50+ expect ( unixfs . mode ) . to . equal ( 0o600 )
51+ expect ( unixfs . mtime ?. secs ) . to . equal ( 1000n )
52+ expect ( unixfs . mtime ?. nsecs ) . to . equal ( 500 )
4053 } )
4154} )
0 commit comments