|
| 1 | +// @ts-nocheck |
| 2 | + |
| 3 | +import test from 'ava' |
| 4 | +import { deleteAllIndices, refreshIndices } 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 | + t.context.collectionId = randomId('collection') |
| 15 | + |
| 16 | + const collection = await loadFixture( |
| 17 | + 'landsat-8-l1-collection.json', |
| 18 | + { id: t.context.collectionId } |
| 19 | + ) |
| 20 | + |
| 21 | + await ingestItem({ |
| 22 | + ingestQueueUrl: t.context.ingestQueueUrl, |
| 23 | + ingestTopicArn: t.context.ingestTopicArn, |
| 24 | + item: collection |
| 25 | + }) |
| 26 | + |
| 27 | + // Ingest items with different dates |
| 28 | + const item1 = await loadFixture('stac/LC80100102015002LGN00.json', { |
| 29 | + collection: t.context.collectionId, |
| 30 | + properties: { |
| 31 | + datetime: '2015-01-02T15:49:05.000Z' |
| 32 | + } |
| 33 | + }) |
| 34 | + |
| 35 | + const item2 = await loadFixture('stac/LC80100102015002LGN00.json', { |
| 36 | + collection: t.context.collectionId, |
| 37 | + id: 'item-2', |
| 38 | + properties: { |
| 39 | + datetime: '2020-06-15T10:30:00.000Z' |
| 40 | + } |
| 41 | + }) |
| 42 | + |
| 43 | + const item3 = await loadFixture('stac/LC80100102015002LGN00.json', { |
| 44 | + collection: t.context.collectionId, |
| 45 | + id: 'item-3', |
| 46 | + properties: { |
| 47 | + datetime: '2018-03-20T08:15:00.000Z' |
| 48 | + } |
| 49 | + }) |
| 50 | + |
| 51 | + await ingestItem({ |
| 52 | + ingestQueueUrl: t.context.ingestQueueUrl, |
| 53 | + ingestTopicArn: t.context.ingestTopicArn, |
| 54 | + item: item1 |
| 55 | + }) |
| 56 | + |
| 57 | + await ingestItem({ |
| 58 | + ingestQueueUrl: t.context.ingestQueueUrl, |
| 59 | + ingestTopicArn: t.context.ingestTopicArn, |
| 60 | + item: item2 |
| 61 | + }) |
| 62 | + |
| 63 | + await ingestItem({ |
| 64 | + ingestQueueUrl: t.context.ingestQueueUrl, |
| 65 | + ingestTopicArn: t.context.ingestTopicArn, |
| 66 | + item: item3 |
| 67 | + }) |
| 68 | + |
| 69 | + await refreshIndices() |
| 70 | +}) |
| 71 | + |
| 72 | +test.after.always(async (t) => { |
| 73 | + if (t.context.api) await t.context.api.close() |
| 74 | +}) |
| 75 | + |
| 76 | +test('GET /collections/:collectionId returns temporal extent from items', async (t) => { |
| 77 | + const { collectionId } = t.context |
| 78 | + |
| 79 | + const response = await t.context.api.client.get(`collections/${collectionId}`, |
| 80 | + { resolveBodyOnly: false }) |
| 81 | + |
| 82 | + t.is(response.statusCode, 200) |
| 83 | + t.is(response.body.id, collectionId) |
| 84 | + |
| 85 | + // Check that extent.temporal.interval exists and is populated |
| 86 | + t.truthy(response.body.extent) |
| 87 | + t.truthy(response.body.extent.temporal) |
| 88 | + t.truthy(response.body.extent.temporal.interval) |
| 89 | + t.is(response.body.extent.temporal.interval.length, 1) |
| 90 | + |
| 91 | + const [startDate, endDate] = response.body.extent.temporal.interval[0] |
| 92 | + |
| 93 | + // Verify the start date is the earliest item datetime (2015-01-02) |
| 94 | + t.is(startDate, '2015-01-02T15:49:05.000Z') |
| 95 | + |
| 96 | + // Verify the end date is the latest item datetime (2020-06-15) |
| 97 | + t.is(endDate, '2020-06-15T10:30:00.000Z') |
| 98 | +}) |
| 99 | + |
| 100 | +test('GET /collections returns temporal extent for all collections', async (t) => { |
| 101 | + const response = await t.context.api.client.get('collections', |
| 102 | + { resolveBodyOnly: false }) |
| 103 | + |
| 104 | + t.is(response.statusCode, 200) |
| 105 | + t.truthy(response.body.collections) |
| 106 | + t.true(response.body.collections.length > 0) |
| 107 | + |
| 108 | + // Find our test collection |
| 109 | + const collection = response.body.collections.find((c) => c.id === t.context.collectionId) |
| 110 | + t.truthy(collection) |
| 111 | + |
| 112 | + // Check that extent.temporal.interval exists and is populated |
| 113 | + t.truthy(collection.extent) |
| 114 | + t.truthy(collection.extent.temporal) |
| 115 | + t.truthy(collection.extent.temporal.interval) |
| 116 | + t.is(collection.extent.temporal.interval.length, 1) |
| 117 | + |
| 118 | + const [startDate, endDate] = collection.extent.temporal.interval[0] |
| 119 | + |
| 120 | + // Verify the dates match the items |
| 121 | + t.is(startDate, '2015-01-02T15:49:05.000Z') |
| 122 | + t.is(endDate, '2020-06-15T10:30:00.000Z') |
| 123 | +}) |
| 124 | + |
| 125 | +test('Collection with no items has null temporal extent', async (t) => { |
| 126 | + // Create a new collection with no items |
| 127 | + const emptyCollectionId = randomId('empty-collection') |
| 128 | + const emptyCollection = await loadFixture( |
| 129 | + 'landsat-8-l1-collection.json', |
| 130 | + { id: emptyCollectionId } |
| 131 | + ) |
| 132 | + |
| 133 | + await ingestItem({ |
| 134 | + ingestQueueUrl: t.context.ingestQueueUrl, |
| 135 | + ingestTopicArn: t.context.ingestTopicArn, |
| 136 | + item: emptyCollection |
| 137 | + }) |
| 138 | + |
| 139 | + await refreshIndices() |
| 140 | + |
| 141 | + const response = await t.context.api.client.get(`collections/${emptyCollectionId}`, |
| 142 | + { resolveBodyOnly: false }) |
| 143 | + |
| 144 | + t.is(response.statusCode, 200) |
| 145 | + t.is(response.body.id, emptyCollectionId) |
| 146 | + |
| 147 | + // For a collection with no items, temporal extent should still exist from the original collection |
| 148 | + // but our code should gracefully handle this (return null or keep original) |
| 149 | + t.truthy(response.body.extent) |
| 150 | +}) |
0 commit comments