-
Notifications
You must be signed in to change notification settings - Fork 537
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
Follow up to add nav parameter #23845
Conversation
packages/drivers/odsp-driver/src/createOdspCreateContainerRequest.ts
Outdated
Show resolved
Hide resolved
packages/drivers/odsp-driver/src/createOdspCreateContainerRequest.ts
Outdated
Show resolved
Hide resolved
packages/drivers/odsp-driver/src/odspDocumentServiceFactoryCore.ts
Outdated
Show resolved
Hide resolved
@@ -498,7 +486,6 @@ describe("Create New Utils Tests", () => { | |||
false /* forceAccessTokenViaAuthorizationHeader */, | |||
undefined /* isClpCompliantApp */, | |||
true /* enableSingleRequestForShareLinkWithCreate */, | |||
mockOdspResolvedUrl, | |||
), | |||
{ | |||
itemId: "mockItemId", |
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.
After you have made the review changes above, let's add a test with the following flow:
- initialize OdspDriverUrlResolverForShareLink() and use it to create a resolve the request generated via createOdspCreateContainerRequest
- mock attach() api response
- then in the
container.resolvedUrl
- check if we have all the desired properties.
Checkout examples in odspCreateContainer.spec.ts.
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.
Since in the unit test, there is no container, you can alternatively check service. resolvedUrl. Service is returned by the createContainer method in the serviceFactory.
🔗 No broken links found! ✅ Your attention to detail is admirable. linkcheck output
|
@@ -82,6 +83,7 @@ export class OdspDriverUrlResolverForShareLink implements IUrlResolver { | |||
resolvedUrl: IOdspResolvedUrl, | |||
dataStorePath: string, | |||
) => Promise<string | undefined>, | |||
private readonly containerPackageInfo?: IContainerPackageInfo | undefined, |
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.
| undefined
type shouldn't be needed here since the property is already optional right?
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.
I'm guessing it's there because the call to get context might return undefined, but the function can still exist.
@@ -257,7 +259,8 @@ export class OdspDriverUrlResolverForShareLink implements IUrlResolver { | |||
|
|||
const containerPackageName: string | undefined = | |||
getContainerPackageName(packageInfoSource) ?? | |||
odspResolvedUrl.codeHint?.containerPackageName; | |||
odspResolvedUrl.codeHint?.containerPackageName ?? | |||
getContainerPackageName(this.containerPackageInfo); |
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.
Add comment explaining why the chaining here is done.
Something like, "containerPackage information can be either provided via the constructor or to the method's params. We give priority to the locally provided params, and fallback to the constructor provided value" (re-phrase maybe to make it more understandable).
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.
Added change
@@ -37,7 +37,7 @@ export function createOdspCreateContainerRequest( | |||
const createNewRequest: IRequest = { | |||
url: `${siteUrl}?driveId=${encodeURIComponent(driveId)}&path=${encodeURIComponent( | |||
filePath, | |||
)}${containerPackageInfo ? `&containerPackageName=${getContainerPackageName(containerPackageInfo)}` : ""}${shareLinkRequestParams ? `&${shareLinkRequestParams}` : ""}`, | |||
)}${shareLinkRequestParams ? `&${shareLinkRequestParams}` : ""}`, |
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.
@MarioJGMsoft Linter might be unhappy about the unused containerPackageInfo - you can rename the parameter starting with an _ to avoid the issue
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.
Applied change
|
||
// Compare the values to make sure that the nav parameter was added correctly | ||
assert.equal( | ||
decodedValue, | ||
"s=%2FsiteUrl&d=driveId&f=mockItemId&c=%2F&fluid=1&a=mockAppName&p=mockContainerPackageName&x=mockContext", | ||
"s=%2FsiteUrl&d=driveId&f=itemId&c=%2F&fluid=1&a=appName&p=containerPackageName&x=context", |
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.
@MarioJGMsoft , Let us also test for scenarios where appName is not provided, but all other params are. Same with containerPackageName. Just to ensure the nav param is not misconstructed.
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.
Applied change
/nav=([^&]*)/, | ||
)?.[1] as string; | ||
// Decode the Base64 value to UTF-8, \r�� is being stored at the end of the string so we slice it off | ||
const decodedValue = fromBase64ToUtf8(base64Value).slice(0, -3); |
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.
Where is \r�� coming from?
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.
I'm not sure, it's being added when I decode the value of navParam, so I'm not sure at what point of the code flow it's being added to the encoded nav param. I don't think it can become an issue but let me know if you think otherwise.
@@ -187,6 +187,7 @@ export class OdspDocumentServiceFactoryCore | |||
!!this.hostPolicy.sessionOptions?.forceAccessTokenViaAuthorizationHeader, | |||
odspResolvedUrl.isClpCompliantApp, | |||
this.hostPolicy.enableSingleRequestForShareLinkWithCreate, | |||
odspResolvedUrl, |
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.
Even though it is not related to this PR, I really would like us to change the name of this variable from odspResolveUrl
to something else that represents the original name. Something like resolvedUrlForCreateNew
. Let me know if that doesn't sound right to you.
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.
I agree that the name can and should be changed to something more related, but I also think that it might be best to leave that change to another PR. Will create the follow up task for it.
); | ||
|
||
const expectedResponse = { | ||
context: "http://sp.devinstall/_api/v2.1/$metadata#", |
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.
Any reason for using this exact URL? Could we use a dummy one.
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.
Yes, we could use a dummy one and I added the change.
identityType: "Enterprise", | ||
}; | ||
|
||
const getContext = async ( |
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.
The function is defined as async, but I don't see any promises used
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.
In the constructor of OdspDriverUrlResolverForShareLink, getContext is a function call that returns a Promise of <strin | undefined>, so the getContext function has to be async.
logger, | ||
"appName", | ||
getContext, | ||
{ name: "containerPackageName" }, |
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.
{ name: "containerPackageName" } /*IContainerPackageInfo*/,
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.
applied change
// Update the webUrl to the version that has the nav parameter that was supposed to be added | ||
mockSharingLinkData.webUrl = | ||
"https://mock.url/?nav=cz0lMkZzaXRlVXJsJmQ9ZHJpdmVJZCZmPW1vY2tJdGVtSWQmYz0lMkYmZmx1aWQ9MSZhPW1vY2tBcHBOYW1lJnA9bW9ja0NvbnRhaW5lclBhY2thZ2VOYW1lJng9bW9ja0NvbnRleHQ%3D"; | ||
const resolved = await shareLinkResolver.resolve(request); |
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.
Add a comment above this like explaining that we are trying to emulate the 'container' behavior where we first create a resolved object for the provided request to invoke driver's createContainer request.
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.
Applied change
This reverts commit 3c2d546.
## Description This task is a follow up to [microsoft#20323](https://dev.azure.com/fluidframework/235294da-091d-4c29-84fc-cdfc3d90890b/_workitems/edit/20323) . When loop tried to implement the code some errors came up, the expected information was not being added. Acceptance criteria The link works properly when loop tries to implement and use it. Execution plan Update the methods we are using to receive the appName and the containerPackageName. Also update IODSPResolvedURL to be able to have the containerPackageName. ## Reviewer Guidance Please let me know if there's something that is missing or that I should keep in mind. Thanks! Fixes: [AB#29956](https://dev.azure.com/fluidframework/235294da-091d-4c29-84fc-cdfc3d90890b/_workitems/edit/29956) --------- Co-authored-by: Jatin Garg <[email protected]>
Description
This task is a follow up to #20323 .
When loop tried to implement the code some errors came up, the expected information was not being added.
Acceptance criteria
The link works properly when loop tries to implement and use it.
Execution plan
Update the methods we are using to receive the appName and the containerPackageName. Also update IODSPResolvedURL to be able to have the containerPackageName.
Reviewer Guidance
Please let me know if there's something that is missing or that I should keep in mind. Thanks!
Fixes: AB#29956