-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from packagelabs/collection-http-media
Update NFTCollectionDisplayView to support HTTP media
- Loading branch information
Showing
6 changed files
with
364 additions
and
8 deletions.
There are no files selected for viewing
8 changes: 6 additions & 2 deletions
8
cadence/metadata-views/MetadataViews.NFTCollectionDisplay.partial.cdc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`NFTCollectionDisplayView generates a Cadence snippet with an HTTP media file 1`] = ` | ||
"pub fun resolveNFTCollectionDisplay(): MetadataViews.NFTCollectionDisplay { | ||
let media = MetadataViews.Media( | ||
file: MetadataViews.HTTPFile(url: \\"http://foo.com/nft.jpeg\\"), | ||
mediaType: \\"image/jpeg\\" | ||
) | ||
return MetadataViews.NFTCollectionDisplay( | ||
name: \\"Foo NFT Collection\\", | ||
description: \\"This is the Foo NFT collection.\\", | ||
externalURL: MetadataViews.ExternalURL(\\"http://foo.com\\"), | ||
squareImage: media, | ||
bannerImage: media, | ||
socials: {} | ||
) | ||
} | ||
" | ||
`; | ||
|
||
exports[`NFTCollectionDisplayView generates a Cadence snippet with an IPFS media file with a path 1`] = ` | ||
"pub fun resolveNFTCollectionDisplay(): MetadataViews.NFTCollectionDisplay { | ||
let media = MetadataViews.Media( | ||
file: MetadataViews.IPFSFile( | ||
cid: \\"bafkreicrfbblmaduqg2kmeqbymdifawex7rxqq2743mitmeia4zdybmmre\\", | ||
path: \\"foo.jpeg\\" | ||
), | ||
mediaType: \\"image/jpeg\\" | ||
) | ||
return MetadataViews.NFTCollectionDisplay( | ||
name: \\"Foo NFT Collection\\", | ||
description: \\"This is the Foo NFT collection.\\", | ||
externalURL: MetadataViews.ExternalURL(\\"http://foo.com\\"), | ||
squareImage: media, | ||
bannerImage: media, | ||
socials: {} | ||
) | ||
} | ||
" | ||
`; | ||
|
||
exports[`NFTCollectionDisplayView generates a Cadence snippet with an IPFS media file with no path 1`] = ` | ||
"pub fun resolveNFTCollectionDisplay(): MetadataViews.NFTCollectionDisplay { | ||
let media = MetadataViews.Media( | ||
file: MetadataViews.IPFSFile( | ||
cid: \\"bafkreicrfbblmaduqg2kmeqbymdifawex7rxqq2743mitmeia4zdybmmre\\", | ||
path: nil | ||
), | ||
mediaType: \\"image/jpeg\\" | ||
) | ||
return MetadataViews.NFTCollectionDisplay( | ||
name: \\"Foo NFT Collection\\", | ||
description: \\"This is the Foo NFT collection.\\", | ||
externalURL: MetadataViews.ExternalURL(\\"http://foo.com\\"), | ||
squareImage: media, | ||
bannerImage: media, | ||
socials: {} | ||
) | ||
} | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import TemplateGenerator from '../generators/TemplateGenerator'; | ||
import * as metadata from './index'; | ||
|
||
const name = 'Foo NFT Collection'; | ||
const description = 'This is the Foo NFT collection.'; | ||
const url = 'http://foo.com'; | ||
const ipfsMedia = 'bafkreicrfbblmaduqg2kmeqbymdifawex7rxqq2743mitmeia4zdybmmre'; | ||
const httpMedia = 'http://foo.com/nft.jpeg'; | ||
const mediaType = 'image/jpeg'; | ||
|
||
function generateView(view: metadata.View): string { | ||
return TemplateGenerator.generate(view.type.cadenceTemplatePath, { view }); | ||
} | ||
|
||
describe('NFTCollectionDisplayView', () => { | ||
it('rejects combined IPFS and HTTP media input', () => { | ||
expect(() => { | ||
metadata.NFTCollectionDisplayView({ | ||
name, | ||
description, | ||
url, | ||
media: { | ||
ipfs: { | ||
cid: ipfsMedia, | ||
}, | ||
url: httpMedia, | ||
type: mediaType, | ||
}, | ||
}); | ||
}).toThrow(); | ||
}); | ||
|
||
const ipfsView = metadata.NFTCollectionDisplayView({ | ||
name, | ||
description, | ||
url, | ||
media: { | ||
ipfs: { | ||
cid: ipfsMedia, | ||
}, | ||
type: mediaType, | ||
}, | ||
}); | ||
|
||
const ipfsWithPathView = metadata.NFTCollectionDisplayView({ | ||
name, | ||
description, | ||
url, | ||
media: { | ||
ipfs: { | ||
cid: ipfsMedia, | ||
path: 'foo.jpeg', | ||
}, | ||
type: mediaType, | ||
}, | ||
}); | ||
|
||
const compactIpfsView = metadata.NFTCollectionDisplayView({ | ||
name, | ||
description, | ||
url, | ||
media: { | ||
ipfs: ipfsMedia, | ||
type: mediaType, | ||
}, | ||
}); | ||
|
||
const legacyIpfsView = metadata.NFTCollectionDisplayView({ | ||
name, | ||
description, | ||
url, | ||
media: { | ||
ipfsCid: ipfsMedia, | ||
type: mediaType, | ||
}, | ||
}); | ||
|
||
it('generates a Cadence snippet with an IPFS media file with no path', () => { | ||
expect(generateView(ipfsView)).toMatchSnapshot(); | ||
}); | ||
|
||
it('generates a Cadence snippet with an IPFS media file with a path', () => { | ||
expect(generateView(ipfsWithPathView)).toMatchSnapshot(); | ||
}); | ||
|
||
it('generates a Cadence snippet with an IPFS media file passed as a CID string only', () => { | ||
expect(compactIpfsView).toEqual(ipfsView); | ||
expect(generateView(compactIpfsView)).toEqual(generateView(ipfsView)); | ||
}); | ||
|
||
it('generates a Cadence snippet with an IPFS media file using legacy input', () => { | ||
// Legacy view should be equivalent to non-legacy view | ||
expect(legacyIpfsView).toEqual(ipfsView); | ||
expect(generateView(legacyIpfsView)).toEqual(generateView(ipfsView)); | ||
}); | ||
|
||
it('generates a Cadence snippet with an HTTP media file', () => { | ||
const view = metadata.NFTCollectionDisplayView({ | ||
name, | ||
description, | ||
url, | ||
media: { | ||
url: httpMedia, | ||
type: mediaType, | ||
}, | ||
}); | ||
|
||
expect(generateView(view)).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.