-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathtest-api-item-get.js
More file actions
173 lines (134 loc) · 4.91 KB
/
test-api-item-get.js
File metadata and controls
173 lines (134 loc) · 4.91 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// @ts-nocheck
import test from 'ava'
import { deleteAllIndices } from '../helpers/database.js'
import { ingestItem } from '../helpers/ingest.js'
import { randomId, loadFixture } from '../helpers/utils.js'
import { setup } from '../helpers/system-tests.js'
test.before(async (t) => {
await deleteAllIndices()
const standUpResult = await setup()
t.context = standUpResult
t.context.collectionId = randomId('collection')
const collection = await loadFixture(
'landsat-8-l1-collection.json',
{ id: t.context.collectionId }
)
await ingestItem({
ingestQueueUrl: t.context.ingestQueueUrl,
ingestTopicArn: t.context.ingestTopicArn,
item: collection
})
t.context.itemId = randomId('item')
const item = await loadFixture(
'stac/LC80100102015082LGN00.json',
{
id: t.context.itemId,
collection: t.context.collectionId
}
)
await ingestItem({
ingestQueueUrl: t.context.ingestQueueUrl,
ingestTopicArn: t.context.ingestTopicArn,
item
})
})
test.beforeEach(async (_) => {
delete process.env['ENABLE_COLLECTIONS_AUTHX']
})
test.after.always(async (t) => {
if (t.context.api) await t.context.api.close()
})
test('GET /collections/:collectionId/items/:itemId', async (t) => {
const { collectionId, itemId } = t.context
const response = await t.context.api.client.get(
`collections/${collectionId}/items/${itemId}`,
{ resolveBodyOnly: false }
)
t.is(response.statusCode, 200)
t.is(response.headers['content-type'], 'application/geo+json; charset=utf-8')
t.is(response.body.type, 'Feature')
t.is(response.body.id, itemId)
t.is(response.body.collection, collectionId)
})
test('GET /collections/:collectionId/items/:itemId for a non-existent id returns not found', async (t) => {
const { collectionId } = t.context
const response = await t.context.api.client.get(
`collections/${collectionId}/items/DOES_NOT_EXIST`,
{ resolveBodyOnly: false, throwHttpErrors: false }
)
t.is(response.statusCode, 404)
})
test('GET /collections/:collectionId/items/:itemId for a non-existent collection returns not found', async (t) => {
const response = await t.context.api.client.get(
'collections/DOES_NOT_EXIST/items/DOES_NOT_EXIST',
{ resolveBodyOnly: false, throwHttpErrors: false }
)
t.is(response.statusCode, 404)
})
test('GET /collections/:collectionId/items/:itemId with restriction returns filtered collections', async (t) => {
process.env['ENABLE_COLLECTIONS_AUTHX'] = 'true'
const { collectionId, itemId } = t.context
const path = `collections/${collectionId}/items/${itemId}`
t.is((await t.context.api.client.get(path,
{ resolveBodyOnly: false, throwHttpErrors: false })).statusCode, 404)
t.is((await t.context.api.client.get(path,
{ resolveBodyOnly: false,
throwHttpErrors: false,
searchParams: { _collections: '' }
})).statusCode, 404)
t.is((await t.context.api.client.get(path,
{
resolveBodyOnly: false,
searchParams: { _collections: '*' }
})).statusCode, 200)
t.is((await t.context.api.client.get(path,
{
resolveBodyOnly: false,
searchParams: { _collections: `${collectionId},foo,bar` }
})).statusCode, 200)
t.is((await t.context.api.client.get(path,
{ resolveBodyOnly: false,
throwHttpErrors: false,
searchParams: { _collections: 'not-a-collection' }
})).statusCode, 404)
})
test('GET /collections/:collectionId/items/:itemId/thumbnail with restriction returns filtered collections', async (t) => {
process.env['ENABLE_COLLECTIONS_AUTHX'] = 'true'
process.env['ENABLE_THUMBNAILS'] = 'true'
const { collectionId, itemId } = t.context
const path = `collections/${collectionId}/items/${itemId}/thumbnail`
t.is((await t.context.api.client.get(path,
{ resolveBodyOnly: false, throwHttpErrors: false
})).statusCode, 404)
t.is((await t.context.api.client.get(path,
{
resolveBodyOnly: false,
throwHttpErrors: false,
searchParams: { _collections: '' }
})).statusCode, 404)
t.is((await t.context.api.client.get(path,
{
resolveBodyOnly: false,
followRedirect: false,
searchParams: { _collections: '*' }
})).statusCode, 302)
t.is((await t.context.api.client.get(path,
{
resolveBodyOnly: false,
followRedirect: false,
searchParams: { _collections: `${collectionId},foo,bar` }
})).statusCode, 302)
t.is((await t.context.api.client.get(path,
{ resolveBodyOnly: false,
followRedirect: false,
throwHttpErrors: false,
searchParams: { _collections: 'not-a-collection' }
})).statusCode, 404)
})
test('GET /collections/:collectionId/items/:itemId/thumbnail disabled', async (t) => {
process.env['ENABLE_THUMBNAILS'] = 'false'
const { collectionId, itemId } = t.context
const path = `collections/${collectionId}/items/${itemId}/thumbnail`
t.is((await t.context.api.client.get(path,
{ resolveBodyOnly: false, throwHttpErrors: false })).statusCode, 404)
})