mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-08 12:07:06 +00:00
Pass subscriptionId when publishing/accessing published notebooks (#288)
We need to record `subscriptionId` when publishing a notebook, also we want to restrict notebooks to only from a particular `subscriptionId` when accessing `My published work` tab. This change passes the `subscriptionId` as part of the URL when publishing or accessing published notebooks.
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import ko from "knockout";
|
||||
import { HttpHeaders, HttpStatusCodes } from "../Common/Constants";
|
||||
import { IPinnedRepo, JunoClient } from "./JunoClient";
|
||||
import { IPinnedRepo, JunoClient, IPublishNotebookRequest } from "./JunoClient";
|
||||
import { configContext } from "../ConfigContext";
|
||||
import { getAuthorizationHeader } from "../Utils/AuthorizationUtils";
|
||||
import { DatabaseAccount } from "../Contracts/DataModels";
|
||||
import { updateUserContext, userContext } from "../UserContext";
|
||||
|
||||
const sampleSubscriptionId = "subscriptionId";
|
||||
|
||||
const sampleDatabaseAccount: DatabaseAccount = {
|
||||
id: "id",
|
||||
@@ -131,11 +134,20 @@ describe("GitHub", () => {
|
||||
|
||||
describe("Gallery", () => {
|
||||
const junoClient = new JunoClient(ko.observable<DatabaseAccount>(sampleDatabaseAccount));
|
||||
const originalSubscriptionId = userContext.subscriptionId;
|
||||
|
||||
beforeAll(() => {
|
||||
updateUserContext({ subscriptionId: sampleSubscriptionId });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
updateUserContext({ subscriptionId: originalSubscriptionId });
|
||||
});
|
||||
|
||||
it("getSampleNotebooks", async () => {
|
||||
window.fetch = jest.fn().mockReturnValue({
|
||||
status: HttpStatusCodes.OK,
|
||||
@@ -295,12 +307,15 @@ describe("Gallery", () => {
|
||||
|
||||
const authorizationHeader = getAuthorizationHeader();
|
||||
expect(response.status).toBe(HttpStatusCodes.OK);
|
||||
expect(window.fetch).toBeCalledWith(`${configContext.JUNO_ENDPOINT}/api/notebooks/gallery/published`, {
|
||||
headers: {
|
||||
[authorizationHeader.header]: authorizationHeader.token,
|
||||
[HttpHeaders.contentType]: "application/json"
|
||||
expect(window.fetch).toBeCalledWith(
|
||||
`${configContext.JUNO_ENDPOINT}/api/notebooks/${sampleSubscriptionId}/gallery/published`,
|
||||
{
|
||||
headers: {
|
||||
[authorizationHeader.header]: authorizationHeader.token,
|
||||
[HttpHeaders.contentType]: "application/json"
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
});
|
||||
|
||||
it("deleteNotebook", async () => {
|
||||
@@ -330,17 +345,26 @@ describe("Gallery", () => {
|
||||
const author = "author";
|
||||
const thumbnailUrl = "thumbnailUrl";
|
||||
const content = `{ "key": "value" }`;
|
||||
const addLinkToNotebookViewer = false;
|
||||
window.fetch = jest.fn().mockReturnValue({
|
||||
status: HttpStatusCodes.OK,
|
||||
json: () => undefined as any
|
||||
});
|
||||
|
||||
const response = await junoClient.publishNotebook(name, description, tags, author, thumbnailUrl, content, false);
|
||||
const response = await junoClient.publishNotebook(
|
||||
name,
|
||||
description,
|
||||
tags,
|
||||
author,
|
||||
thumbnailUrl,
|
||||
content,
|
||||
addLinkToNotebookViewer
|
||||
);
|
||||
|
||||
const authorizationHeader = getAuthorizationHeader();
|
||||
expect(response.status).toBe(HttpStatusCodes.OK);
|
||||
expect(window.fetch).toBeCalledWith(
|
||||
`${configContext.JUNO_ENDPOINT}/api/notebooks/${sampleDatabaseAccount.name}/gallery`,
|
||||
`${configContext.JUNO_ENDPOINT}/api/notebooks/${sampleSubscriptionId}/${sampleDatabaseAccount.name}/gallery`,
|
||||
{
|
||||
method: "PUT",
|
||||
headers: {
|
||||
@@ -353,8 +377,9 @@ describe("Gallery", () => {
|
||||
tags,
|
||||
author,
|
||||
thumbnailUrl,
|
||||
content: JSON.parse(content)
|
||||
})
|
||||
content: JSON.parse(content),
|
||||
addLinkToNotebookViewer
|
||||
} as IPublishNotebookRequest)
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user