-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectionApi.test.ts
More file actions
76 lines (62 loc) · 1.95 KB
/
CollectionApi.test.ts
File metadata and controls
76 lines (62 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { expect, it, describe, beforeAll, jest } from '@jest/globals'
import {
createCollectionResultSchema,
listCollectionsResultSchema,
} from '__models__/collections-responses.zod'
import { CollectionsApi } from 'apis/collections/api'
import { ApiClient } from 'client'
let client: CollectionsApi
jest.retryTimes(3, { logErrorsBeforeRetry: true })
beforeAll(() => {
if (!process.env.API_TOKEN) {
throw new Error('API_TOKEN environment variable not set')
}
client = new CollectionsApi(new ApiClient(process.env.API_TOKEN))
})
describe('Assets Collections: ', () => {
const testAssetId = '0fc38f70-a092-40e5-b579-3fea806b1295'
let testCollectionId: string
it('Lists collections with only the type parameter set', async () => {
const result = await client.listCollections({ type: 'private' })
expect(() =>
listCollectionsResultSchema.strict().parse(result)
).not.toThrow()
})
it('Lists collections with parameters', async () => {
const result = await client.listCollections({
type: 'private',
limit: 50,
offset: 1,
})
expect(() =>
listCollectionsResultSchema.strict().parse(result)
).not.toThrow()
})
it('Creates a collection', async () => {
const title = `sdk-test-${new Date().toISOString()}`
const result = await client.createCollection({
title,
description: 'SDK Test',
})
testCollectionId = result.uuid
expect(() =>
createCollectionResultSchema.strict().parse(result)
).not.toThrow()
})
it('Adds an asset to a collection', async () => {
await expect(
client.addOrRemoveAssets({
collections: [testCollectionId],
assets_to_add: [testAssetId],
})
).resolves.not.toThrow()
})
it('Removes an asset from a collection', async () => {
await expect(
client.addOrRemoveAssets({
collections: [testCollectionId],
assets_to_remove: [testAssetId],
})
).resolves.not.toThrow()
})
})