Skip to content

Commit

Permalink
WIP - sourceUrl1,2 static icon tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kimura-developer committed Aug 28, 2023
1 parent 5b7aadb commit fbf975e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions service/test/adapters/icons/adapters.icons.db.mongoose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,15 @@ describe('static icon mongoose repository', function() {

it('replaces icon properties for an existing source url when the content hash changes', async function() {

const sourceUrl = new URL('mage:///test/replace.png')
const sourceUrl1 = new URL('mage:///test/replace.png')
const sourceUrl2 = new URL('mage:///test/replace.png')

// Trigger searchParams getter on both
sourceUrl1.searchParams.toString();
sourceUrl2.searchParams.toString();

const origAttrs: Required<StaticIconStub> = {
sourceUrl,
sourceUrl: sourceUrl1,
imageType: 'raster',
sizeBytes: 1000,
sizePixels: { width: 120, height: 120 },
Expand All @@ -142,9 +148,9 @@ describe('static icon mongoose repository', function() {
fileName: 'orig.png',
title: 'Original',
summary: 'replace me'
}
};
const updatedAttrs: Required<StaticIconStub> = {
sourceUrl,
sourceUrl: sourceUrl2,
imageType: 'vector',
sizeBytes: 1100,
sizePixels: { width: 220, height: 220 },
Expand Down Expand Up @@ -298,6 +304,7 @@ describe('static icon mongoose repository', function() {
it('does not update the icon properties if the stub has no content hash', async function() {

const sourceUrl = new URL('mage:///test/replace.png')

const origAttrs: Required<StaticIconStub> = Object.freeze({
sourceUrl,
imageType: 'raster',
Expand Down Expand Up @@ -331,6 +338,12 @@ describe('static icon mongoose repository', function() {
const updated = await repo.findOrImportBySourceUrl(updatedAttrs)
const updatedFound = await model.find({})

const serializeForComparison = (obj: typeof origFound[0]) => {
const serialized = obj.toJSON();
serialized.sourceUrl = serialized.sourceUrl.href; // Convert the URL to string
return serialized;
};

expect(orig).to.deep.equal({ id, registeredTimestamp: origFound[0].registeredTimestamp, ...origAttrs })
expect(updated).to.deep.equal(orig)
expect(origFound).to.have.length(1)
Expand Down

0 comments on commit fbf975e

Please sign in to comment.