|
| 1 | +/* |
| 2 | + * Copyright (c) 2023, salesforce.com, inc. |
| 3 | + * All rights reserved. |
| 4 | + * Licensed under the BSD 3-Clause license. |
| 5 | + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause |
| 6 | + */ |
| 7 | +import { expect } from 'chai'; |
| 8 | +import { Connection, Org } from '@salesforce/core'; |
| 9 | +import sinon from 'sinon'; |
| 10 | +import { ExperienceSite } from '../../src/shared/experience/expSite.js'; |
| 11 | + |
| 12 | +describe('getRemoteMetadata', () => { |
| 13 | + it('should return remote metadata when it exists', async () => { |
| 14 | + const org = new Org(); |
| 15 | + const siteName = 'site@with#special-chars'; |
| 16 | + const experienceSite = new ExperienceSite(org, siteName); |
| 17 | + |
| 18 | + // Create a mock Connection instance using sinon |
| 19 | + const mockConnection = sinon.createStubInstance(Connection); |
| 20 | + |
| 21 | + // Configure the mock to return the desired result when calling query |
| 22 | + mockConnection.query.resolves({ |
| 23 | + done: true, |
| 24 | + totalSize: 1, |
| 25 | + records: [ |
| 26 | + { |
| 27 | + Name: 'MRT_experience_00DSG00000ECBfZ_0DMSG000001CfA6_site_with_special_chars_10-30_12-47', |
| 28 | + LastModifiedDate: '2024-11-12', |
| 29 | + }, |
| 30 | + ], |
| 31 | + }); |
| 32 | + |
| 33 | + // Replace the original connection with the mocked connection |
| 34 | + org.getConnection = () => mockConnection; |
| 35 | + |
| 36 | + const remoteMetadata = await experienceSite.getRemoteMetadata(); |
| 37 | + |
| 38 | + // Check if the called query matches the expected pattern |
| 39 | + const calledQuery = mockConnection.query.args[0][0]; |
| 40 | + const expectedPattern = |
| 41 | + /SELECT Name, LastModifiedDate FROM StaticResource WHERE Name LIKE 'MRT_experience_%_site_with_special_chars/; |
| 42 | + expect(calledQuery).to.match(expectedPattern); |
| 43 | + |
| 44 | + expect(remoteMetadata).to.deep.equal({ |
| 45 | + bundleName: 'MRT_experience_00DSG00000ECBfZ_0DMSG000001CfA6_site_with_special_chars_10-30_12-47', |
| 46 | + bundleLastModified: '2024-11-12', |
| 47 | + }); |
| 48 | + }); |
| 49 | +}); |
0 commit comments