From 59113d7bbf0d89bc430027ada71cee4d69a8d061 Mon Sep 17 00:00:00 2001 From: Tanuj Mittal Date: Fri, 29 Jan 2021 20:28:20 +0530 Subject: [PATCH] Update Juno endpoints (#405) --- src/Juno/JunoClient.test.ts | 57 +++++++++++++++++++++---------------- src/Juno/JunoClient.ts | 16 ++++------- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/src/Juno/JunoClient.test.ts b/src/Juno/JunoClient.test.ts index 999627974..155a12b7f 100644 --- a/src/Juno/JunoClient.test.ts +++ b/src/Juno/JunoClient.test.ts @@ -225,7 +225,7 @@ describe("Gallery", () => { const authorizationHeader = getAuthorizationHeader(); expect(response.status).toBe(HttpStatusCodes.OK); expect(window.fetch).toBeCalledWith( - `${configContext.JUNO_ENDPOINT}/api/notebooks/${sampleDatabaseAccount.name}/gallery/${id}/downloads`, + `${configContext.JUNO_ENDPOINT}/api/notebooks/subscriptions/${sampleSubscriptionId}/databaseAccounts/${sampleDatabaseAccount.name}/gallery/${id}/downloads`, { method: "PATCH", headers: { @@ -248,7 +248,7 @@ describe("Gallery", () => { const authorizationHeader = getAuthorizationHeader(); expect(response.status).toBe(HttpStatusCodes.OK); expect(window.fetch).toBeCalledWith( - `${configContext.JUNO_ENDPOINT}/api/notebooks/${sampleSubscriptionId}/${sampleDatabaseAccount.name}/gallery/${id}/favorite`, + `${configContext.JUNO_ENDPOINT}/api/notebooks/subscriptions/${sampleSubscriptionId}/databaseAccounts/${sampleDatabaseAccount.name}/gallery/${id}/favorite`, { method: "PATCH", headers: { @@ -270,13 +270,16 @@ describe("Gallery", () => { const authorizationHeader = getAuthorizationHeader(); expect(response.status).toBe(HttpStatusCodes.OK); - expect(window.fetch).toBeCalledWith(`${configContext.JUNO_ENDPOINT}/api/notebooks/gallery/${id}/unfavorite`, { - method: "PATCH", - headers: { - [authorizationHeader.header]: authorizationHeader.token, - [HttpHeaders.contentType]: "application/json", - }, - }); + expect(window.fetch).toBeCalledWith( + `${configContext.JUNO_ENDPOINT}/api/notebooks/subscriptions/${sampleSubscriptionId}/databaseAccounts/${sampleDatabaseAccount.name}/gallery/${id}/unfavorite`, + { + method: "PATCH", + headers: { + [authorizationHeader.header]: authorizationHeader.token, + [HttpHeaders.contentType]: "application/json", + }, + } + ); }); it("getFavoriteNotebooks", async () => { @@ -289,12 +292,15 @@ describe("Gallery", () => { const authorizationHeader = getAuthorizationHeader(); expect(response.status).toBe(HttpStatusCodes.OK); - expect(window.fetch).toBeCalledWith(`${configContext.JUNO_ENDPOINT}/api/notebooks/gallery/favorites`, { - headers: { - [authorizationHeader.header]: authorizationHeader.token, - [HttpHeaders.contentType]: "application/json", - }, - }); + expect(window.fetch).toBeCalledWith( + `${configContext.JUNO_ENDPOINT}/api/notebooks/subscriptions/${sampleSubscriptionId}/databaseAccounts/${sampleDatabaseAccount.name}/gallery/favorites`, + { + headers: { + [authorizationHeader.header]: authorizationHeader.token, + [HttpHeaders.contentType]: "application/json", + }, + } + ); }); it("getPublishedNotebooks", async () => { @@ -308,7 +314,7 @@ describe("Gallery", () => { const authorizationHeader = getAuthorizationHeader(); expect(response.status).toBe(HttpStatusCodes.OK); expect(window.fetch).toBeCalledWith( - `${configContext.JUNO_ENDPOINT}/api/notebooks/${sampleSubscriptionId}/gallery/published`, + `${configContext.JUNO_ENDPOINT}/api/notebooks/subscriptions/${sampleSubscriptionId}/databaseAccounts/${sampleDatabaseAccount.name}/gallery/published`, { headers: { [authorizationHeader.header]: authorizationHeader.token, @@ -329,13 +335,16 @@ describe("Gallery", () => { const authorizationHeader = getAuthorizationHeader(); expect(response.status).toBe(HttpStatusCodes.OK); - expect(window.fetch).toBeCalledWith(`${configContext.JUNO_ENDPOINT}/api/notebooks/gallery/${id}`, { - method: "DELETE", - headers: { - [authorizationHeader.header]: authorizationHeader.token, - [HttpHeaders.contentType]: "application/json", - }, - }); + expect(window.fetch).toBeCalledWith( + `${configContext.JUNO_ENDPOINT}/api/notebooks/subscriptions/${sampleSubscriptionId}/databaseAccounts/${sampleDatabaseAccount.name}/gallery/${id}`, + { + method: "DELETE", + headers: { + [authorizationHeader.header]: authorizationHeader.token, + [HttpHeaders.contentType]: "application/json", + }, + } + ); }); it("publishNotebook", async () => { @@ -364,7 +373,7 @@ describe("Gallery", () => { const authorizationHeader = getAuthorizationHeader(); expect(response.status).toBe(HttpStatusCodes.OK); expect(window.fetch).toBeCalledWith( - `${configContext.JUNO_ENDPOINT}/api/notebooks/${sampleSubscriptionId}/${sampleDatabaseAccount.name}/gallery`, + `${configContext.JUNO_ENDPOINT}/api/notebooks/subscriptions/${sampleSubscriptionId}/databaseAccounts/${sampleDatabaseAccount.name}/gallery`, { method: "PUT", headers: { diff --git a/src/Juno/JunoClient.ts b/src/Juno/JunoClient.ts index 8b9d0a590..b0ebc99d0 100644 --- a/src/Juno/JunoClient.ts +++ b/src/Juno/JunoClient.ts @@ -283,7 +283,7 @@ export class JunoClient { } public async increaseNotebookDownloadCount(id: string): Promise> { - const response = await window.fetch(`${this.getNotebooksAccountUrl()}/gallery/${id}/downloads`, { + const response = await window.fetch(`${this.getNotebooksSubscriptionIdAccountUrl()}/gallery/${id}/downloads`, { method: "PATCH", headers: JunoClient.getHeaders(), }); @@ -317,7 +317,7 @@ export class JunoClient { } public async unfavoriteNotebook(id: string): Promise> { - const response = await window.fetch(`${this.getNotebooksUrl()}/gallery/${id}/unfavorite`, { + const response = await window.fetch(`${this.getNotebooksSubscriptionIdAccountUrl()}/gallery/${id}/unfavorite`, { method: "PATCH", headers: JunoClient.getHeaders(), }); @@ -334,19 +334,19 @@ export class JunoClient { } public async getFavoriteNotebooks(): Promise> { - return await this.getNotebooks(`${this.getNotebooksUrl()}/gallery/favorites`, { + return await this.getNotebooks(`${this.getNotebooksSubscriptionIdAccountUrl()}/gallery/favorites`, { headers: JunoClient.getHeaders(), }); } public async getPublishedNotebooks(): Promise> { - return await this.getNotebooks(`${this.getNotebooksUrl()}/${this.getSubscriptionId()}/gallery/published`, { + return await this.getNotebooks(`${this.getNotebooksSubscriptionIdAccountUrl()}/gallery/published`, { headers: JunoClient.getHeaders(), }); } public async deleteNotebook(id: string): Promise> { - const response = await window.fetch(`${this.getNotebooksUrl()}/gallery/${id}`, { + const response = await window.fetch(`${this.getNotebooksSubscriptionIdAccountUrl()}/gallery/${id}`, { method: "DELETE", headers: JunoClient.getHeaders(), }); @@ -501,12 +501,8 @@ export class JunoClient { return userContext.subscriptionId; } - private getNotebooksAccountUrl(): string { - return `${this.getNotebooksUrl()}/${this.getAccount()}`; - } - private getNotebooksSubscriptionIdAccountUrl(): string { - return `${this.getNotebooksUrl()}/${this.getSubscriptionId()}/${this.getAccount()}`; + return `${this.getNotebooksUrl()}/subscriptions/${this.getSubscriptionId()}/databaseAccounts/${this.getAccount()}`; } private getAnalyticsUrl(): string {