Skip to content

Commit

Permalink
CMR-10122: Fixes lint
Browse files Browse the repository at this point in the history
  • Loading branch information
dmistry1 committed Oct 10, 2024
1 parent bdb761b commit 74462cd
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 62 deletions.
97 changes: 49 additions & 48 deletions src/domains/__tests__/collections.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,7 @@ describe("collectionsToStac", () => {

// Check if all expected fields are present and correctly populated
expect(stacCollection).to.have.property("type", "Collection");
expect(stacCollection).to.have.property(
"id",
`${mockCollection.entryId}`
);
expect(stacCollection).to.have.property("id", `${mockCollection.entryId}`);
expect(stacCollection).to.have.property("title", mockCollection.title);
expect(stacCollection).to.have.property("description", mockCollection.description);
expect(stacCollection).to.have.property("stac_version", "1.0.0");
Expand Down Expand Up @@ -313,48 +310,48 @@ 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', () => {
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',
type: "Earth Observation Satellites",
shortName: "Terra",
longName: "Earth Observing System, Terra (AM-1)",
instruments: [
{
{
shortName: "ASTER",
longName: "Advanced Spaceborne Thermal Emission and Reflection Radiometer"
longName: "Advanced Spaceborne Thermal Emission and Reflection Radiometer",
},
{
{
shortName: "MODIS",
longName: "Moderate-Resolution Imaging Spectroradiometer"
}
]
}
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',
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");
Expand All @@ -365,74 +362,78 @@ describe("collectionsToStac", () => {
const [mockCollection] = generateCollections(1);
mockCollection.platforms = [
{
type:"Earth Observation Satellites",
type: "Earth Observation Satellites",
shortName: "Terra",
longName:'Earth Observing System, Terra (AM-1)',
longName: "Earth Observing System, Terra (AM-1)",
instruments: [
{
{
shortName: "ASTER",
longName: "Advanced Spaceborne Thermal Emission and Reflection Radiometer"
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"
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-2",
longName: "VEGETATION INSTRUMENT 2 (SPOT 5)",
},
{
shortName: "VEGETATION-3",
longName: "VEGETATION INSTRUMENT 3 (SPOT 3)",
},
{
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"]);
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",
type: "Earth Observation Satellites",
shortName: "Terra",
longName:'Earth Observing System, Terra (AM-1)',
longName: "Earth Observing System, Terra (AM-1)",
instruments: [
{
{
shortName: "ASTER",
longName: "Advanced Spaceborne Thermal Emission and Reflection Radiometer"
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: []
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"]);
});
})
});
});
15 changes: 5 additions & 10 deletions src/domains/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ const createSummaries = (collection: Collection): Summaries => {
{ platform: [], instruments: [] }
);

if(summaries.instruments.length === 0 ){
summaries.instruments = ["Not Provided"]
if (summaries.instruments.length === 0) {
summaries.instruments = ["Not Provided"];
}

return summaries
return summaries;
};

const generateProviders = (collection: Collection) => [
Expand All @@ -232,12 +232,7 @@ const generateProviders = (collection: Collection) => [
* Convert a GraphQL collection item into a STACCollection.
*/
export const collectionToStac = (collection: Collection): STACCollection => {

const {
entryId,
description,
title
} = collection;
const { entryId, description, title } = collection;

const { license, licenseLink } = extractLicense(collection);

Expand Down Expand Up @@ -307,7 +302,7 @@ export const getCollections = async (
return { cursor, count, items: collections as STACCollection[] };
};

const attachId = (collection: { entryId: string; }) => ({
const attachId = (collection: { entryId: string }) => ({
...collection,
id: collection.entryId,
});
Expand Down
3 changes: 0 additions & 3 deletions src/domains/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,9 @@ const selfLinks = (req: Request, item: STACItem) => {

const { id, collection } = item;

console.log("🚀 ~ selfLinks ~ collection:", collection)

const providerId = provider["provider-id"];
const itemId = encodeURIComponent(id);
const collectionId = encodeURIComponent(collection as string);
console.log("🚀 ~ selfLinks ~ collectionId:", collectionId)

return [
{
Expand Down
2 changes: 1 addition & 1 deletion src/utils/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const generateGranules = (
conceptId: `G00000000${idx}-${opts?.provider ?? "TEST_PROV"}`,
collection: {
conceptId: opts?.collection?.conceptId ?? "C123456789-TEST_PROV",
entryId: 'TEST_COLLECTION_1'
entryId: "TEST_COLLECTION_1",
},
title: faker.random.words(8).replace(/\s+/gi, "_"),
} as Granule;
Expand Down

0 comments on commit 74462cd

Please sign in to comment.