@xyo-network/crypto-nft-diviner-score-plugin 4.2.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +17 -13
- package/src/lib/rating/criteria/scoring/metadata/attributes/spec/evaluateAttributes.spec.ts +81 -0
- package/src/lib/rating/criteria/scoring/metadata/lib/spec/urlHelpers.spec.ts +102 -0
- package/src/lib/rating/criteria/scoring/metadata/spec/animationUrl.spec.ts +43 -0
- package/src/lib/rating/criteria/scoring/metadata/spec/backgroundColor.spec.ts +36 -0
- package/src/lib/rating/criteria/scoring/metadata/spec/description.spec.ts +29 -0
- package/src/lib/rating/criteria/scoring/metadata/spec/externalUrl.spec.ts +44 -0
- package/src/lib/rating/criteria/scoring/metadata/spec/image.spec.ts +55 -0
- package/src/lib/rating/criteria/scoring/metadata/spec/imageData.spec.ts +37 -0
- package/src/lib/rating/criteria/scoring/metadata/spec/name.spec.ts +28 -0
- package/src/lib/rating/criteria/scoring/metadata/spec/youtubeUrl.spec.ts +44 -0
- package/src/lib/rating/spec/evaluateNft.spec.ts +140 -0
- package/src/spec/Diviner.spec.ts +41 -0
- package/src/spec/Plugin.spec.ts +17 -0
- package/src/spec/testData.json +20109 -0
- package/typedoc.json +0 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/crypto-nft-diviner-score-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Typescript/Javascript Plugins for XYO Platform",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -28,24 +28,28 @@
|
|
|
28
28
|
},
|
|
29
29
|
"module": "dist/neutral/index.mjs",
|
|
30
30
|
"types": "dist/neutral/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"src"
|
|
34
|
+
],
|
|
31
35
|
"dependencies": {
|
|
32
|
-
"@xyo-network/crypto-nft-payload-plugin": "^
|
|
33
|
-
"@xyo-network/crypto-nft-score-model": "^
|
|
34
|
-
"@xyo-network/diviner-abstract": "^
|
|
35
|
-
"@xyo-network/diviner-model": "^
|
|
36
|
-
"@xyo-network/module-model": "^
|
|
37
|
-
"@xyo-network/payload-builder": "^
|
|
38
|
-
"@xyo-network/payload-model": "^
|
|
39
|
-
"@xyo-network/payloadset-plugin": "^
|
|
36
|
+
"@xyo-network/crypto-nft-payload-plugin": "^5.0.0",
|
|
37
|
+
"@xyo-network/crypto-nft-score-model": "^5.0.0",
|
|
38
|
+
"@xyo-network/diviner-abstract": "^5.0.0",
|
|
39
|
+
"@xyo-network/diviner-model": "^5.0.0",
|
|
40
|
+
"@xyo-network/module-model": "^5.0.0",
|
|
41
|
+
"@xyo-network/payload-builder": "^5.0.0",
|
|
42
|
+
"@xyo-network/payload-model": "^5.0.0",
|
|
43
|
+
"@xyo-network/payloadset-plugin": "^5.0.0",
|
|
40
44
|
"ethers": "^6.15.0",
|
|
41
45
|
"svg-parser": "^2.0.4"
|
|
42
46
|
},
|
|
43
47
|
"devDependencies": {
|
|
44
48
|
"@types/svg-parser": "^2.0.6",
|
|
45
|
-
"@xylabs/ts-scripts-yarn3": "^7.0.
|
|
46
|
-
"@xylabs/tsconfig": "^7.0.
|
|
47
|
-
"@xylabs/vitest-extended": "^
|
|
48
|
-
"@xyo-network/payload-wrapper": "^
|
|
49
|
+
"@xylabs/ts-scripts-yarn3": "^7.0.2",
|
|
50
|
+
"@xylabs/tsconfig": "^7.0.2",
|
|
51
|
+
"@xylabs/vitest-extended": "^5.0.0",
|
|
52
|
+
"@xyo-network/payload-wrapper": "^5.0.0",
|
|
49
53
|
"typescript": "^5.8.3",
|
|
50
54
|
"vitest": "^3.2.4"
|
|
51
55
|
},
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import type { NftAttribute } from '@xyo-network/crypto-nft-payload-plugin'
|
|
4
|
+
import {
|
|
5
|
+
describe, expect,
|
|
6
|
+
it,
|
|
7
|
+
} from 'vitest'
|
|
8
|
+
|
|
9
|
+
import { evaluateAttributes } from '../evaluateAttributes.ts'
|
|
10
|
+
|
|
11
|
+
const attributes: NftAttribute[][] = [
|
|
12
|
+
[
|
|
13
|
+
{
|
|
14
|
+
display_type: 'date',
|
|
15
|
+
trait_type: 'Created Date',
|
|
16
|
+
value: null,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
display_type: 'number',
|
|
20
|
+
trait_type: 'Length',
|
|
21
|
+
value: 8,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
display_type: 'date',
|
|
25
|
+
trait_type: 'Registration Date',
|
|
26
|
+
value: 1_640_668_437_000,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
display_type: 'date',
|
|
30
|
+
trait_type: 'Expiration Date',
|
|
31
|
+
value: 1_956_237_957_000,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
[
|
|
35
|
+
{
|
|
36
|
+
display_type: 'date',
|
|
37
|
+
trait_type: 'Publish Date',
|
|
38
|
+
value: 1_643_274_000,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
trait_type: 'Edition',
|
|
42
|
+
value: 'Bridge',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
trait_type: 'Inventory',
|
|
46
|
+
value: 'Artifacts',
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
{
|
|
51
|
+
trait_type: 'Artist',
|
|
52
|
+
value: 'MrSnowy10',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
trait_type: 'Item Eaten',
|
|
56
|
+
value: 'Radioactive Waste',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
trait_type: 'Type',
|
|
60
|
+
value: 'Avatar',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
trait_type: 'Species',
|
|
64
|
+
value: 'Pinco',
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
describe('evaluateAttributes', () => {
|
|
70
|
+
describe('evaluateAttributes', () => {
|
|
71
|
+
it.each(attributes)('evaluates the attributes', (...value) => {
|
|
72
|
+
const score = evaluateAttributes(value)
|
|
73
|
+
const [amount, possible] = score
|
|
74
|
+
expect(amount).toBeNumber()
|
|
75
|
+
expect(amount).toBePositive()
|
|
76
|
+
expect(possible).toBeNumber()
|
|
77
|
+
expect(possible).toBePositive()
|
|
78
|
+
expect(amount).toBeGreaterThanOrEqual(possible)
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
})
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
describe, expect,
|
|
5
|
+
it,
|
|
6
|
+
} from 'vitest'
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
isSecure, isValidUrl, isWeb2, isWeb3, toUrl,
|
|
10
|
+
} from '../urlHelpers.ts'
|
|
11
|
+
|
|
12
|
+
const ipfsUrl = 'ipfs://QmRyBBrLYWy6zZRyDUR5JWLJ2mrbvHFtptosrM3jAwBXTc/'
|
|
13
|
+
|
|
14
|
+
const httpUrl = 'http://www.google.com'
|
|
15
|
+
const httpsUrl = 'https://xyo.network'
|
|
16
|
+
|
|
17
|
+
const validUrls = [httpUrl, httpsUrl, ipfsUrl]
|
|
18
|
+
const invalidUrls = [undefined, null, 'not a url', 'https://']
|
|
19
|
+
|
|
20
|
+
describe('toUrl', () => {
|
|
21
|
+
describe('with valid url', () => {
|
|
22
|
+
it.each(validUrls)('parses the URL', (url) => {
|
|
23
|
+
const parsed = toUrl(url)
|
|
24
|
+
expect(parsed).toBeObject()
|
|
25
|
+
expect(parsed?.host).toBeString()
|
|
26
|
+
expect(parsed?.hostname).toBeString()
|
|
27
|
+
expect(parsed?.protocol).toBeString()
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
describe('with invalid url', () => {
|
|
31
|
+
it.each(invalidUrls)('returns undefined', (url) => {
|
|
32
|
+
const parsed = toUrl(url)
|
|
33
|
+
expect(parsed).toBeUndefined()
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
describe('isValidUrl', () => {
|
|
39
|
+
describe('with valid url', () => {
|
|
40
|
+
it.each(validUrls)('returns true', (url) => {
|
|
41
|
+
const parsed = isValidUrl(url)
|
|
42
|
+
expect(parsed).toBeTrue()
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
describe('with invalid url', () => {
|
|
46
|
+
it.each(invalidUrls)('returns false', (url) => {
|
|
47
|
+
const parsed = isValidUrl(url)
|
|
48
|
+
expect(parsed).toBeFalse()
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
describe('isWeb3', () => {
|
|
54
|
+
describe('with ipfs url', () => {
|
|
55
|
+
it('returns true', () => {
|
|
56
|
+
const parsed = isWeb3(ipfsUrl)
|
|
57
|
+
expect(parsed).toBeTrue()
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
describe('with https url', () => {
|
|
61
|
+
it.each([httpUrl, httpsUrl])('returns false', (url) => {
|
|
62
|
+
const parsed = isWeb3(url)
|
|
63
|
+
expect(parsed).toBeFalse()
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
describe('isWeb2', () => {
|
|
69
|
+
describe('with ipfs url', () => {
|
|
70
|
+
it('returns false', () => {
|
|
71
|
+
const parsed = isWeb2(ipfsUrl)
|
|
72
|
+
expect(parsed).toBeFalse()
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
describe('with https url', () => {
|
|
76
|
+
it.each([httpUrl, httpsUrl])('returns true', (url) => {
|
|
77
|
+
const parsed = isWeb2(url)
|
|
78
|
+
expect(parsed).toBeTrue()
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
describe('isSecure', () => {
|
|
84
|
+
describe('with https url', () => {
|
|
85
|
+
it('returns true', () => {
|
|
86
|
+
const parsed = isSecure(httpsUrl)
|
|
87
|
+
expect(parsed).toBeTrue()
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
describe('with ipfs url', () => {
|
|
91
|
+
it('returns true', () => {
|
|
92
|
+
const parsed = isSecure(ipfsUrl)
|
|
93
|
+
expect(parsed).toBeTrue()
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
describe('with http url', () => {
|
|
97
|
+
it('returns false', () => {
|
|
98
|
+
const parsed = isSecure(httpUrl)
|
|
99
|
+
expect(parsed).toBeFalse()
|
|
100
|
+
})
|
|
101
|
+
})
|
|
102
|
+
})
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
describe,
|
|
5
|
+
it,
|
|
6
|
+
} from 'vitest'
|
|
7
|
+
|
|
8
|
+
import { scoreAnimationUrl } from '../animationUrl.ts'
|
|
9
|
+
import {
|
|
10
|
+
expectLoweredScore, expectMaxPossibleScore, expectNoScore,
|
|
11
|
+
} from './testHelpers.ts'
|
|
12
|
+
|
|
13
|
+
const web3Urls = ['ipfs://QmaXTuWjEbDuvcA3dHypqHfxMzDLq78Zj5kBLN4JdMEYDB/3.mp4', 'ipfs://QmTxDYfccVVWoucpbvFECxtysRkMBADDL8j4zVYSRM7Kp3/']
|
|
14
|
+
const web2Urls = ['https://media.niftygateway.com/video/upload/v1659986036/Julian/KennyScharfWestinghouse/WESTINGHOUSE_20-26X44.5X4.5B_x2mz3r.mp4']
|
|
15
|
+
const invalidUrls = ['', 'not a url', {}]
|
|
16
|
+
const missingUrls = [undefined, null]
|
|
17
|
+
|
|
18
|
+
describe('scoreAnimationUrl', () => {
|
|
19
|
+
describe('with valid web3 url', () => {
|
|
20
|
+
it.each(web3Urls)('return max possible score', (value) => {
|
|
21
|
+
const score = scoreAnimationUrl(value)
|
|
22
|
+
expectMaxPossibleScore(score)
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
describe('with valid web2 url', () => {
|
|
26
|
+
it.each(web2Urls)('returns lowered score', (value) => {
|
|
27
|
+
const score = scoreAnimationUrl(value)
|
|
28
|
+
expectLoweredScore(score)
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
describe('with invalid url', () => {
|
|
32
|
+
it.each(invalidUrls)('returns lowered score', (value) => {
|
|
33
|
+
const score = scoreAnimationUrl(value)
|
|
34
|
+
expectLoweredScore(score)
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
describe('with no url', () => {
|
|
38
|
+
it.each(missingUrls)('returns no score', (value) => {
|
|
39
|
+
const score = scoreAnimationUrl(value)
|
|
40
|
+
expectNoScore(score)
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
})
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
describe,
|
|
5
|
+
it,
|
|
6
|
+
} from 'vitest'
|
|
7
|
+
|
|
8
|
+
import { scoreBackgroundColor } from '../backgroundColor.ts'
|
|
9
|
+
import {
|
|
10
|
+
expectLoweredScore, expectMaxPossibleScore, expectNoScore,
|
|
11
|
+
} from './testHelpers.ts'
|
|
12
|
+
|
|
13
|
+
const valid = ['ffffff', 'FFFFFF']
|
|
14
|
+
const invalid = ['#ffffff', '#FFFFFF', '', 'not a color', {}]
|
|
15
|
+
const missing = [undefined, null]
|
|
16
|
+
|
|
17
|
+
describe('scoreBackgroundColor', () => {
|
|
18
|
+
describe('with valid background_color', () => {
|
|
19
|
+
it.each(valid)('returns max possible score', (value) => {
|
|
20
|
+
const score = scoreBackgroundColor(value)
|
|
21
|
+
expectMaxPossibleScore(score)
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
describe('with invalid background_color', () => {
|
|
25
|
+
it.each(invalid)('returns lowered score', (value) => {
|
|
26
|
+
const score = scoreBackgroundColor(value)
|
|
27
|
+
expectLoweredScore(score)
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
describe('with missing background_color', () => {
|
|
31
|
+
it.each(missing)('returns no score', (value) => {
|
|
32
|
+
const score = scoreBackgroundColor(value)
|
|
33
|
+
expectNoScore(score)
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import { describe, it } from 'vitest'
|
|
4
|
+
|
|
5
|
+
import { scoreDescription } from '../description.ts'
|
|
6
|
+
import { expectMaxPossibleScore, expectMiniumScore } from './testHelpers.ts'
|
|
7
|
+
|
|
8
|
+
const valid = [
|
|
9
|
+
// eslint-disable-next-line @stylistic/max-len
|
|
10
|
+
'*This drop features new payment methods including Metamask, Apple Pay, Google Pay, Buy Now Pay Later, Nifty Balance, and Gemini Balance! On top of this, you will now be able to purchase multiple editions in a single transaction. Prepaid ETH will not be an allowed payment method for the Open Edition.*\r\n\r\n---\r\n\r\nBriefing: UnderAqua is an underwater universe born out of chaos from the mind of Kenny Scharf. This unique one of a kind story of a post nuclear universe is told through NFT’s and the participation from its collectors, AKA scientists. This concept represents what is possible when a community comes together to accomplish a goal for the greater good.\r\n\r\nThe Year: 2045\r\n\r\nThe Place: An abandoned nuclear power plant off the coast of the Pacific.\r\n\r\nThe Situation: Unforeseen tectonic movements and intensifying ocean waves crashing against the complex have eroded the bordering wall of a nuclear facility – and small cracks have begun to spider along with the concrete. Unbeknownst to all, highly toxic ooze has been seeping into the surrounding waters, converging with a century of untended plastic pollution. When scientists at the plant finally discover the leak – years after it began – they find that the doomed wildlife has been ravaged by hazardous plastics and radiation from the nuclear plant, permanently mutating the fish, with some exhibiting erratic behaviors and unnatural abilities. For example, some fish have become mutated and others have built underwater metropolises. Some fish have grown legs while others have grown wings. Some smoke weed and some take steroids. The impact of the superpowers combined with their newly found free will is something never before seen. Now it is up to us, a massive task force of analysts known as “UnderAqua,” to study the effects of radiation on the fish. Each of the experts will be granted full access to the plant’s staff, tools, and the quarantined areas, which are presumed to house infected species of fish.\r\n\r\nThe Mission: The lead scientist has a hypothesis that although these fish’s superpowers can be dangerous, if studied correctly, we can find answers to some of humanity’s biggest threats. So our goal is to study these fish and figure out not only what specific mutation happened, but figure out how we can apply these superpower-like abilities to help the society for the greater good of humanity.',
|
|
11
|
+
'Airdrop for holders',
|
|
12
|
+
]
|
|
13
|
+
const invalid = [{}]
|
|
14
|
+
const missing = ['', undefined, null]
|
|
15
|
+
|
|
16
|
+
describe('scoreDescription', () => {
|
|
17
|
+
describe('with valid description', () => {
|
|
18
|
+
it.each(valid)('returns max possible score', (value) => {
|
|
19
|
+
const score = scoreDescription(value)
|
|
20
|
+
expectMaxPossibleScore(score)
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
describe('with missing or invalid description', () => {
|
|
24
|
+
it.each([...missing, ...invalid])('returns minimum score', (value) => {
|
|
25
|
+
const score = scoreDescription(value)
|
|
26
|
+
expectMiniumScore(score)
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
describe,
|
|
5
|
+
it,
|
|
6
|
+
} from 'vitest'
|
|
7
|
+
|
|
8
|
+
import { scoreExternalUrl } from '../externalUrl.ts'
|
|
9
|
+
import {
|
|
10
|
+
expectLoweredScore, expectMaxPossibleScore, expectMiniumScore,
|
|
11
|
+
} from './testHelpers.ts'
|
|
12
|
+
|
|
13
|
+
const secure = ['https://lostpoets.xyz/']
|
|
14
|
+
|
|
15
|
+
const insecure = ['http://lvcidia.xyz/']
|
|
16
|
+
const invalid = ['', 'not a url', {}]
|
|
17
|
+
const missing = [undefined, null]
|
|
18
|
+
|
|
19
|
+
describe('scoreExternalUrl', () => {
|
|
20
|
+
describe('with secure url', () => {
|
|
21
|
+
it.each(secure)('returns max possible score', (value) => {
|
|
22
|
+
const score = scoreExternalUrl(value)
|
|
23
|
+
expectMaxPossibleScore(score)
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
describe('with valid url', () => {
|
|
27
|
+
it.each(insecure)('returns lowered score', (value) => {
|
|
28
|
+
const score = scoreExternalUrl(value)
|
|
29
|
+
expectLoweredScore(score)
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
describe('with invalid url', () => {
|
|
33
|
+
it.each(invalid)('returns minium score', (value) => {
|
|
34
|
+
const score = scoreExternalUrl(value)
|
|
35
|
+
expectMiniumScore(score)
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
describe('with no url', () => {
|
|
39
|
+
it.each(missing)('returns minimum score', (value) => {
|
|
40
|
+
const score = scoreExternalUrl(value)
|
|
41
|
+
expectMiniumScore(score)
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
})
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
describe,
|
|
5
|
+
it,
|
|
6
|
+
} from 'vitest'
|
|
7
|
+
|
|
8
|
+
import { scoreImage } from '../image.ts'
|
|
9
|
+
import {
|
|
10
|
+
expectLoweredScore, expectMaxPossibleScore, expectMiniumScore,
|
|
11
|
+
} from './testHelpers.ts'
|
|
12
|
+
|
|
13
|
+
const web3Urls = ['ipfs://QmaXTuWjEbDuvcA3dHypqHfxMzDLq78Zj5kBLN4JdMEYDB/3.mp4', 'ipfs://QmTxDYfccVVWoucpbvFECxtysRkMBADDL8j4zVYSRM7Kp3/']
|
|
14
|
+
const secureWeb2Urls = [
|
|
15
|
+
'https://media.niftygateway.com/video/upload/v1659986036/Julian/KennyScharfWestinghouse/WESTINGHOUSE_20-26X44.5X4.5B_x2mz3r.mp4',
|
|
16
|
+
]
|
|
17
|
+
const insecureWeb2Urls = [
|
|
18
|
+
|
|
19
|
+
'http://media.niftygateway.com/video/upload/v1659986036/Julian/KennyScharfWestinghouse/WESTINGHOUSE_20-26X44.5X4.5B_x2mz3r.mp4',
|
|
20
|
+
]
|
|
21
|
+
const invalidUrls = ['', 'not a url', {}]
|
|
22
|
+
const missingUrls = [undefined, null]
|
|
23
|
+
|
|
24
|
+
describe('scoreImage', () => {
|
|
25
|
+
describe('with web3 url', () => {
|
|
26
|
+
it.each(web3Urls)('return max possible score', (value) => {
|
|
27
|
+
const score = scoreImage(value)
|
|
28
|
+
expectMaxPossibleScore(score)
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
describe('with valid secure url', () => {
|
|
32
|
+
it.each(secureWeb2Urls)('returns lowered score', (value) => {
|
|
33
|
+
const score = scoreImage(value)
|
|
34
|
+
expectLoweredScore(score)
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
describe('with valid insecure url', () => {
|
|
38
|
+
it.each(insecureWeb2Urls)('returns lowered score', (value) => {
|
|
39
|
+
const score = scoreImage(value)
|
|
40
|
+
expectLoweredScore(score)
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
describe('with invalid url', () => {
|
|
44
|
+
it.each(invalidUrls)('returns lowered score', (value) => {
|
|
45
|
+
const score = scoreImage(value)
|
|
46
|
+
expectMiniumScore(score)
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
describe('with no url', () => {
|
|
50
|
+
it.each(missingUrls)('returns no score', (value) => {
|
|
51
|
+
const score = scoreImage(value)
|
|
52
|
+
expectMiniumScore(score)
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
describe,
|
|
5
|
+
it,
|
|
6
|
+
} from 'vitest'
|
|
7
|
+
|
|
8
|
+
import { scoreImageData } from '../imageData.ts'
|
|
9
|
+
import { expectMaxPossibleScore, expectMiniumScore } from './testHelpers.ts'
|
|
10
|
+
|
|
11
|
+
const valid = [
|
|
12
|
+
// eslint-disable-next-line @stylistic/max-len
|
|
13
|
+
"<svg xmlns='http://www.w3.org/2000/svg' version='1.1' width='2000' height='2000'><style>.m1 #c{fill: #fff;}.m1 #r{fill: #000;}.m2 #c{fill: #fc3;}.m2 #r{fill: #000;}.m3 #c{fill: #fff;}.m3 #r{fill: #33f;}.m4 #c{fill: #fff;}.m4 #r{fill: #f33;}.a #c{fill: #000 !important;}.a #r{fill: #fff !important;}</style><g class='m1 c3'><rect id='r' width='2000' height='2000'/><circle id='c' cx='1000' cy='1000' r='146.2449'/></g></svg>",
|
|
14
|
+
]
|
|
15
|
+
const invalid = ['<svg>\n\t\t<path\td=" class="" />\n</svg>', '<svg></svg', '<svg></', '<html></html>', '', 'not an SVG', {}]
|
|
16
|
+
const missing = [undefined, null]
|
|
17
|
+
|
|
18
|
+
describe('scoreImageData', () => {
|
|
19
|
+
describe('with valid image data', () => {
|
|
20
|
+
it.each(valid)('return max possible score', (value) => {
|
|
21
|
+
const score = scoreImageData(value)
|
|
22
|
+
expectMaxPossibleScore(score)
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
describe('with invalid image data', () => {
|
|
26
|
+
it.each(invalid)('returns minimum score', (value) => {
|
|
27
|
+
const score = scoreImageData(value)
|
|
28
|
+
expectMiniumScore(score)
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
describe('with no image data', () => {
|
|
32
|
+
it.each(missing)('returns minimum score', (value) => {
|
|
33
|
+
const score = scoreImageData(value)
|
|
34
|
+
expectMiniumScore(score)
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
describe,
|
|
5
|
+
it,
|
|
6
|
+
} from 'vitest'
|
|
7
|
+
|
|
8
|
+
import { scoreName } from '../name.ts'
|
|
9
|
+
import { expectMaxPossibleScore, expectMiniumScore } from './testHelpers.ts'
|
|
10
|
+
|
|
11
|
+
const valid = ['Foo Friends #3042', '🔥 Fire & Such']
|
|
12
|
+
const invalid = [{}]
|
|
13
|
+
const missing = ['', undefined, null]
|
|
14
|
+
|
|
15
|
+
describe('scoreName', () => {
|
|
16
|
+
describe('with valid name', () => {
|
|
17
|
+
it.each(valid)('returns max possible score', (value) => {
|
|
18
|
+
const score = scoreName(value)
|
|
19
|
+
expectMaxPossibleScore(score)
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
describe('with missing or invalid name', () => {
|
|
23
|
+
it.each([...missing, ...invalid])('returns minimum score', (value) => {
|
|
24
|
+
const score = scoreName(value)
|
|
25
|
+
expectMiniumScore(score)
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
describe,
|
|
5
|
+
it,
|
|
6
|
+
} from 'vitest'
|
|
7
|
+
|
|
8
|
+
import { scoreYoutubeUrl } from '../youtubeUrl.ts'
|
|
9
|
+
import {
|
|
10
|
+
expectLoweredScore, expectMaxPossibleScore, expectMiniumScore, expectNoScore,
|
|
11
|
+
} from './testHelpers.ts'
|
|
12
|
+
|
|
13
|
+
const secure = ['https://lostpoets.xyz/']
|
|
14
|
+
|
|
15
|
+
const insecure = ['http://lvcidia.xyz/']
|
|
16
|
+
const invalid = ['', 'not a url', {}]
|
|
17
|
+
const missing = [undefined, null]
|
|
18
|
+
|
|
19
|
+
describe('scoreYoutubeUrl', () => {
|
|
20
|
+
describe('with secure url', () => {
|
|
21
|
+
it.each(secure)('returns max possible score', (value) => {
|
|
22
|
+
const score = scoreYoutubeUrl(value)
|
|
23
|
+
expectMaxPossibleScore(score)
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
describe('with valid url', () => {
|
|
27
|
+
it.each(insecure)('returns lowered score', (value) => {
|
|
28
|
+
const score = scoreYoutubeUrl(value)
|
|
29
|
+
expectLoweredScore(score)
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
describe('with invalid url', () => {
|
|
33
|
+
it.each(invalid)('returns minium score', (value) => {
|
|
34
|
+
const score = scoreYoutubeUrl(value)
|
|
35
|
+
expectMiniumScore(score)
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
describe('with no url', () => {
|
|
39
|
+
it.each(missing)('returns no score', (value) => {
|
|
40
|
+
const score = scoreYoutubeUrl(value)
|
|
41
|
+
expectNoScore(score)
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
})
|