-
Notifications
You must be signed in to change notification settings - Fork 12
fix: download site bundle correctly if site name has special chars #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import { expect } from 'chai'; | ||
import { Connection, Org } from '@salesforce/core'; | ||
import sinon from 'sinon'; | ||
import { | ||
replaceSpacesAndSpecialChars, | ||
hasSpacesOrSpecialChars, | ||
ExperienceSite, | ||
} from '../../src/shared/experience/expSite.js'; | ||
|
||
describe('replaceSpacesAndSpecialChars', () => { | ||
it('should replace spaces and special characters with underscores', () => { | ||
const input = 'site#name@with-special%chars with spaces'; | ||
const expectedOutput = 'site_name_with_special_chars_with_spaces'; | ||
const output = replaceSpacesAndSpecialChars(input); | ||
expect(output).to.equal(expectedOutput); | ||
}); | ||
}); | ||
|
||
describe('hasSpacesOrSpecialChars', () => { | ||
it('should return true if the input string has spaces', () => { | ||
const input = 'Hello World'; | ||
const output = hasSpacesOrSpecialChars(input); | ||
expect(output).to.be.true; | ||
}); | ||
|
||
it('should return true if the input string has special characters', () => { | ||
const input = 'Hello, @#'; | ||
const output = hasSpacesOrSpecialChars(input); | ||
expect(output).to.be.true; | ||
}); | ||
|
||
it('should return false if the input string has neither spaces nor special characters', () => { | ||
const input = 'HelloWorld'; | ||
const output = hasSpacesOrSpecialChars(input); | ||
expect(output).to.be.false; | ||
}); | ||
}); | ||
|
||
describe('getRemoteMetadata', () => { | ||
it('should return remote metadata when it exists', async () => { | ||
const org = new Org(); | ||
const siteName = 'site@with#special-chars'; | ||
const experienceSite = new ExperienceSite(org, siteName); | ||
|
||
// Create a mock Connection instance using sinon | ||
const mockConnection = sinon.createStubInstance(Connection); | ||
|
||
// Configure the mock to return the desired result when calling query | ||
mockConnection.query.resolves({ | ||
done: true, | ||
totalSize: 1, | ||
records: [ | ||
{ | ||
Name: 'MRT_experience_00DSG00000ECBfZ_0DMSG000001CfA6_site_with_special_chars_10-30_12-47', | ||
LastModifiedDate: '2024-11-12', | ||
}, | ||
], | ||
}); | ||
|
||
// Replace the original connection with the mocked connection | ||
org.getConnection = () => mockConnection; | ||
|
||
const remoteMetadata = await experienceSite.getRemoteMetadata(); | ||
|
||
// Check if the called query matches the expected pattern | ||
const calledQuery = mockConnection.query.args[0][0]; | ||
const expectedPattern = | ||
/SELECT Name, LastModifiedDate FROM StaticResource WHERE Name LIKE 'MRT_experience_%_site_with_special_chars/; | ||
expect(calledQuery).to.match(expectedPattern); | ||
|
||
expect(remoteMetadata).to.deep.equal({ | ||
bundleName: 'MRT_experience_00DSG00000ECBfZ_0DMSG000001CfA6_site_with_special_chars_10-30_12-47', | ||
bundleLastModified: '2024-11-12', | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pulkit0555 Is there a reason why we can't do this in the constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nrkruk I was also debating on the same idea in a different PR to add these changes in the constructor but I guess that was missed. Let me add those changes now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.