|
| 1 | +// @ts-nocheck |
| 2 | + |
| 3 | +import test from 'ava' |
| 4 | +import { deleteAllIndices } from '../helpers/database.js' |
| 5 | +import { ingestItem } from '../helpers/ingest.js' |
| 6 | +import { randomId, loadFixture } from '../helpers/utils.js' |
| 7 | +import { setup } from '../helpers/system-tests.js' |
| 8 | + |
| 9 | +test.before(async (t) => { |
| 10 | + await deleteAllIndices() |
| 11 | + const standUpResult = await setup() |
| 12 | + |
| 13 | + t.context = standUpResult |
| 14 | + |
| 15 | + t.context.collectionId = randomId('collection') |
| 16 | +}) |
| 17 | + |
| 18 | +test.after.always(async (t) => { |
| 19 | + if (t.context.api) await t.context.api.close() |
| 20 | +}) |
| 21 | + |
| 22 | +test('GET /collections/:collectionId/queryables returns queryables', async (t) => { |
| 23 | + const collection = await loadFixture( |
| 24 | + 'landsat-8-l1-collection.json', |
| 25 | + { id: t.context.collectionId } |
| 26 | + ) |
| 27 | + |
| 28 | + await ingestItem({ |
| 29 | + ingestQueueUrl: t.context.ingestQueueUrl, |
| 30 | + ingestTopicArn: t.context.ingestTopicArn, |
| 31 | + item: collection |
| 32 | + }) |
| 33 | + |
| 34 | + const { collectionId } = t.context |
| 35 | + |
| 36 | + const response = await t.context.api.client.get(`collections/${collectionId}/queryables`, |
| 37 | + { resolveBodyOnly: false }) |
| 38 | + |
| 39 | + t.is(response.statusCode, 200) |
| 40 | + t.is(response.headers['content-type'], 'application/schema+json; charset=utf-8') |
| 41 | + // @ts-expect-error We need to validate these responses |
| 42 | + t.true(response.body.$id.endsWith(`/collections/${collectionId}/queryables`)) |
| 43 | + t.is(response.body.title, `Queryables for Collection ${collectionId}`) |
| 44 | + t.is(response.body.$schema, 'https://json-schema.org/draft/2020-12/schema') |
| 45 | + t.is(response.body.type, 'object') |
| 46 | + t.deepEqual(response.body.properties, { |
| 47 | + 'eo:cloud_cover': { |
| 48 | + $ref: 'https://stac-extensions.github.io/eo/v1.0.0/schema.json#/definitions/fields/properties/eo:cloud_cover', |
| 49 | + }, |
| 50 | + }) |
| 51 | + t.is(response.body.additionalProperties, true) |
| 52 | +}) |
| 53 | + |
| 54 | +test('GET /collections/:collectionId/queryables returns queryables even if not defined in Collection', async (t) => { |
| 55 | + const collection = await loadFixture( |
| 56 | + 'collection-without-queryables.json', |
| 57 | + { id: t.context.collectionId } |
| 58 | + ) |
| 59 | + |
| 60 | + await ingestItem({ |
| 61 | + ingestQueueUrl: t.context.ingestQueueUrl, |
| 62 | + ingestTopicArn: t.context.ingestTopicArn, |
| 63 | + item: collection |
| 64 | + }) |
| 65 | + |
| 66 | + const { collectionId } = t.context |
| 67 | + |
| 68 | + const response = await t.context.api.client.get(`collections/${collectionId}/queryables`, |
| 69 | + { resolveBodyOnly: false }) |
| 70 | + |
| 71 | + t.is(response.statusCode, 200) |
| 72 | + t.is(response.headers['content-type'], 'application/schema+json; charset=utf-8') |
| 73 | + // @ts-expect-error We need to validate these responses |
| 74 | + t.true(response.body.$id.endsWith(`/collections/${collectionId}/queryables`)) |
| 75 | + t.is(response.body.title, `Queryables for Collection ${collectionId}`) |
| 76 | + t.is(response.body.$schema, 'https://json-schema.org/draft/2020-12/schema') |
| 77 | + t.is(response.body.type, 'object') |
| 78 | + t.deepEqual(response.body.properties, {}) |
| 79 | + t.is(response.body.additionalProperties, true) |
| 80 | +}) |
| 81 | + |
| 82 | +test('GET /collection/:collectionId/queryables for non-existent collection returns Not Found', async (t) => { |
| 83 | + const response = await t.context.api.client.get( |
| 84 | + 'collections/DOES_NOT_EXIST/queryables', |
| 85 | + { resolveBodyOnly: false, throwHttpErrors: false } |
| 86 | + ) |
| 87 | + |
| 88 | + t.is(response.statusCode, 404) |
| 89 | +}) |
0 commit comments