Skip to content

Commit

Permalink
CMR-10122: Updates tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmistry1 committed Oct 10, 2024
1 parent 4118121 commit bdb761b
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/providerCatalog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe("GET /:provider", () => {
count: mockCollections.length,
cursor: "foundCursor",
items: mockCollections.map((coll) => ({
id: `${coll.shortName}_${coll.version}`,
entryId: `${coll.shortName}_${coll.version}`,
title: coll.title ?? faker.random.words(4),
})),
});
Expand Down
122 changes: 120 additions & 2 deletions src/domains/__tests__/collections.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ describe("collectionsToStac", () => {
expect(stacCollection).to.have.property("type", "Collection");
expect(stacCollection).to.have.property(
"id",
`${mockCollection.shortName}_${mockCollection.version}`
`${mockCollection.entryId}`
);
expect(stacCollection).to.have.property("title", mockCollection.title);
expect(stacCollection).to.have.property("description", mockCollection.description);
Expand Down Expand Up @@ -313,8 +313,126 @@ describe("collectionsToStac", () => {
]);
expect(stacCollection.summaries).to.have.property("instruments");
expect(stacCollection.summaries?.instruments).to.deep.equal([
mockCollection.platforms[0].instruments[0].shortName,
mockCollection.platforms?.[0]?.instruments?.[0]?.shortName
]);
});
});
describe('when processing platform and instruments', () => {
it("should correctly handle a collection with multiple Platforms and Instruments", () => {
const [mockCollection] = generateCollections(1);
mockCollection.platforms = [
{
type:'Earth Observation Satellites',
shortName: "Terra",
longName: "Earth Observing System, Terra (AM-1)",
instruments: [
{
shortName: "ASTER",
longName: "Advanced Spaceborne Thermal Emission and Reflection Radiometer"
},
{
shortName: "MODIS",
longName: "Moderate-Resolution Imaging Spectroradiometer"
}
]
}
];
const stacCollection = collectionToStac(mockCollection);
expect(stacCollection.summaries).to.have.property("platform");
expect(stacCollection.summaries?.platform).to.deep.equal(["Terra"]);
expect(stacCollection.summaries).to.have.property("instruments");
expect(stacCollection.summaries?.instruments).to.deep.equal(["ASTER", "MODIS"]);
})

it("should handle a collection with platforms but no instruments", () => {
const [mockCollection] = generateCollections(1);
mockCollection.platforms = [
{
type:'Earth Observation Satellites',
shortName: "Terra",
longName: "Earth Observing System, Terra (AM-1)",
}
];
const stacCollection = collectionToStac(mockCollection);

expect(stacCollection.summaries).to.have.property("platform");
expect(stacCollection.summaries?.platform).to.deep.equal(["Terra"]);
expect(stacCollection.summaries).to.have.property("instruments");
expect(stacCollection.summaries?.instruments).to.deep.equal(["Not Provided"]);
});

it("should handle a collection with some platforms having instruments and others not", () => {
const [mockCollection] = generateCollections(1);
mockCollection.platforms = [
{
type:"Earth Observation Satellites",
shortName: "Terra",
longName:'Earth Observing System, Terra (AM-1)',
instruments: [
{
shortName: "ASTER",
longName: "Advanced Spaceborne Thermal Emission and Reflection Radiometer"
},
]
},
{
type: "Earth Observation Satellites",
shortName: "SPOT-4",
longName: "Systeme Probatoire Pour l'Observation de la Terre-4"
},
{
type: "Earth Observation Satellites",
shortName: "SPOT-5",
longName: "Systeme Probatoire Pour l'Observation de la Terre-5",
instruments: [
{
shortName: "VEGETATION-2",
longName: "VEGETATION INSTRUMENT 2 (SPOT 5)"
},
{
shortName: "VEGETATION-3",
longName: "VEGETATION INSTRUMENT 3 (SPOT 3)"
}
]
}
];

const stacCollection = collectionToStac(mockCollection);

expect(stacCollection.summaries).to.have.property("platform");
expect(stacCollection.summaries?.platform).to.deep.equal(["Terra", "SPOT-4", "SPOT-5"]);
expect(stacCollection.summaries).to.have.property("instruments");
expect(stacCollection.summaries?.instruments).to.deep.equal(["ASTER", "VEGETATION-2", "VEGETATION-3"]);
});

it("should handle a collection with empty instruments arrays", () => {
const [mockCollection] = generateCollections(1);
mockCollection.platforms = [
{
type:"Earth Observation Satellites",
shortName: "Terra",
longName:'Earth Observing System, Terra (AM-1)',
instruments: [
{
shortName: "ASTER",
longName: "Advanced Spaceborne Thermal Emission and Reflection Radiometer"
},
]
},
{
type: "Earth Observation Satellites",
shortName: "SPOT-4",
longName: "Systeme Probatoire Pour l'Observation de la Terre-4",
instruments: []
},
];

const stacCollection = collectionToStac(mockCollection);

expect(stacCollection.summaries).to.have.property("platform");
expect(stacCollection.summaries?.platform).to.deep.equal(["Terra", "SPOT-4"]);
expect(stacCollection.summaries).to.have.property("instruments");
expect(stacCollection.summaries?.instruments).to.deep.equal(["ASTER"]);
});
})
});
6 changes: 3 additions & 3 deletions src/domains/__tests__/items.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe("granuleToStac", () => {
start_datetime: "2009-09-14T00:00:00.000Z",
end_datetime: "2010-09-14T00:00:00.000Z",
},
collection: "short_1",
collection: "TEST_COLLECTION_1",
links: [
{
href: "undefined/search/concepts/G000000000-TEST_PROV.json",
Expand Down Expand Up @@ -129,7 +129,7 @@ describe("granuleToStac", () => {
start_datetime: "2009-09-14T00:00:00.000Z",
end_datetime: "2010-09-14T00:00:00.000Z",
},
collection: "short_1",
collection: "TEST_COLLECTION_1",
links: [
{
href: "undefined/search/concepts/G000000000-TEST_PROV.json",
Expand Down Expand Up @@ -212,7 +212,7 @@ describe("granuleToStac", () => {
start_datetime: "2009-09-14T00:00:00.000Z",
end_datetime: "2010-09-14T00:00:00.000Z",
},
collection: "short_1",
collection: "TEST_COLLECTION_1",
links: [
{
href: "undefined/search/concepts/G000000000-TEST_PROV.json",
Expand Down
6 changes: 3 additions & 3 deletions src/domains/__tests__/stac.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ describe("sortByToSortKeys", () => {
[
{ input: "properties.eo:cloud_cover", output: ["cloudCover"] },
{ input: "-properties.eo:cloud_cover", output: ["-cloudCover"] },
{ input: "id", output: ["shortName"] },
{ input: "-id", output: ["-shortName"] },
{ input: "id", output: ["entryId"] },
{ input: "-id", output: ["-entryId"] },
{ input: "title", output: ["entryTitle"] },
{ input: "-title", output: ["-entryTitle"] },
{ input: "someOtherField", output: ["someOtherField"] },
Expand All @@ -439,7 +439,7 @@ describe("sortByToSortKeys", () => {
{ field: "id", direction: "asc" },
{ field: "title", direction: "desc" },
];
expect(sortByToSortKeys(input)).to.deep.equal(["-cloudCover", "shortName", "-entryTitle"]);
expect(sortByToSortKeys(input)).to.deep.equal(["-cloudCover", "entryId", "-entryTitle"]);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/models/GraphQLModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export type Platform = {
type: string;
shortName: string;
longName: string;
instruments: Instrument[];
instruments?: Instrument[];
};

export type ScienceKeywords = {
Expand Down
6 changes: 2 additions & 4 deletions src/utils/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ export const generateGranules = (
conceptId: `G00000000${idx}-${opts?.provider ?? "TEST_PROV"}`,
collection: {
conceptId: opts?.collection?.conceptId ?? "C123456789-TEST_PROV",
shortName: "short",
version: "1",
entryId: 'TEST_COLLECTION_1'
},
title: faker.random.words(8).replace(/\s+/gi, "_"),
} as Granule;
Expand All @@ -184,8 +183,7 @@ export const generateCollections = (
summary: faker.lorem.paragraph(),
description: "this is the abstract but aliased as description",
title: "mock_coll",
shortName: faker.random.words(4).replace(/\s+/, "_"),
version: faker.random.alphaNumeric(),
entryId: faker.random.words(4).replace(/\s+/, "_"),
boxes: null,
lines: null,
polygons: null,
Expand Down

0 comments on commit bdb761b

Please sign in to comment.