Skip to content

Commit

Permalink
refactor(envited.ascs.digital): test cids
Browse files Browse the repository at this point in the history
Signed-off-by: Roy Scheeren <[email protected]>
  • Loading branch information
royscheeren committed Dec 19, 2024
1 parent 775a8d0 commit 3340007
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apps/envited.ascs.digital/__mocks__/file-type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const fileTypeFromBuffer = jest.fn().mockResolvedValue({
ext: 'jpg',
mime: 'image/jpeg'
mime: 'image/jpeg',
})
23 changes: 17 additions & 6 deletions apps/envited.ascs.digital/common/asset/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,23 @@ export const getPathAndBufferFromFile = _getPathAndBufferFromFile({

export const _getFilenameFromFile =
({ createFilename }: { createFilename: (byteArray: Uint8Array) => Promise<string> }) =>
async (path: string, type: string, arrayBuffer: ArrayBuffer): Promise<ExtractedFileWithCID> => ({
cid: await createFilename(new Uint8Array(arrayBuffer)),
path,
type,
arrayBuffer,
})
async (path: string, type: string, arrayBuffer: ArrayBuffer): Promise<ExtractedFileWithCID> => {
console.log('path', path)
console.log('arrayBuffer', arrayBuffer)
console.log('uint8Array', new Uint8Array(arrayBuffer))
const cid = await createFilename(new Uint8Array(arrayBuffer))
console.log('cid', cid)

const blob = new Blob([arrayBuffer], { type })
const cid2 = await createFilename(blob as any)
console.log('cid2', cid2)
return {
cid,
path,
type,
arrayBuffer,
}
}

export const getFilenameFromFile = _getFilenameFromFile({
createFilename,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export const _main =
log.info(`Uploading ${path} to IPFS`)
return createGroup(metadata.minter).then(async group => {
log.info(`Uploading ${path} to IPFS with group ${group}`)
console.log(process.env.PINATA_JWT, process.env.PINATA_GATEWAY, process.env.PINATA_GATEWAY_KEY)
const file = await uploadFile({ arrayBuffer, filename: last(split('/', path)) as string, group })
log.info(file)
})
Expand Down
1 change: 0 additions & 1 deletion apps/envited.ascs.digital/common/ipfs/ipfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const createGroup = (pinata: PinataSDK) => async (groupName: string) => {
const group = await pinata.groups.create({
name: groupName,
})
console.log(group)
return group.id
}

Expand Down
9 changes: 5 additions & 4 deletions apps/envited.ascs.digital/listener/listener.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { fileTypeFromBuffer } from 'file-type'

import * as SUT from './listener'

jest.mock('file-type')
import { fileTypeFromBuffer } from 'file-type'

describe('createLocalCopy', () => {
beforeEach(() => {
Expand All @@ -11,11 +12,11 @@ describe('createLocalCopy', () => {

it.only('should download a file from IPFS and upload it to S3', async () => {
// Setup your mock as needed for specific tests
(fileTypeFromBuffer as jest.Mock).mockResolvedValue({
;(fileTypeFromBuffer as jest.Mock).mockResolvedValue({
ext: 'png',
mime: 'image/png'
mime: 'image/png',
})

const cid = 'CID'
const data = 'DATA'
const contentType = 'CONTENT_TYPE'
Expand Down

0 comments on commit 3340007

Please sign in to comment.