-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds support for 'modifyPreviewConfiguration' query (#95)
- Loading branch information
Showing
10 changed files
with
208 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
16 changes: 11 additions & 5 deletions
16
lib/queries/preview/modify-preview-configuration-query.class.ts
This file contains 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 |
---|---|---|
@@ -1,17 +1,23 @@ | ||
import { PreviewResponses } from '../../responses'; | ||
import { IManagementClientConfig } from '../../config'; | ||
import { ManagementQueryService } from '../../services'; | ||
import { BaseQuery } from '../base-query'; | ||
import { PreviewModels } from '../../models'; | ||
|
||
export class ModifyPreviewConfigurationQuery extends BaseQuery<any> { | ||
constructor(protected config: IManagementClientConfig, protected queryService: ManagementQueryService) { | ||
export class ModifyPreviewConfigurationQuery extends BaseQuery<PreviewResponses.ModifyConfigurationResponse> { | ||
constructor( | ||
protected config: IManagementClientConfig, | ||
protected queryService: ManagementQueryService, | ||
private data: PreviewModels.IModifyPreviewConfigurationData | ||
) { | ||
super(config, queryService); | ||
} | ||
|
||
toPromise(): Promise<any> { | ||
return this.queryService.getPreviewConfigurationAsync(this.getUrl(), this.queryConfig); | ||
toPromise(): Promise<PreviewResponses.ModifyConfigurationResponse> { | ||
return this.queryService.modifyPreviewConfigurationAsync(this.getUrl(), this.queryConfig, this.data); | ||
} | ||
|
||
protected getAction(): string { | ||
return this.apiEndpoints.getPreviewConfigruation(); | ||
return this.apiEndpoints.modifyPreviewConfigruation(); | ||
} | ||
} |
This file contains 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 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
42 changes: 42 additions & 0 deletions
42
test/browser/fake-responses/preview/fake-modify-preview-configuration.json
This file contains 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,42 @@ | ||
{ | ||
"space_domains": [ | ||
{ | ||
"space": { | ||
"id": "fb2c6c2b-fb79-4d1b-856a-b59762e304b0" | ||
}, | ||
"domain": "www.mysite1.com" | ||
}, | ||
{ | ||
"space": { | ||
"id": "24dace50-3cf6-4378-8704-453af9cdb60c" | ||
}, | ||
"domain": "www.mysite2.com" | ||
} | ||
], | ||
"preview_url_patterns": [ | ||
{ | ||
"content_type": { | ||
"id": "cf75f19d-6ed4-4820-a541-cde50dd79054" | ||
}, | ||
"url_patterns": [ | ||
{ | ||
"space": { | ||
"id": "24dace50-3cf6-4378-8704-453af9cdb60c" | ||
}, | ||
"url_pattern": "https://{Space}/{Lang}/articles/history/" | ||
} | ||
] | ||
}, | ||
{ | ||
"content_type": { | ||
"id": "f21f6c3b-f63e-4aa1-866f-55fd85ad262e" | ||
}, | ||
"url_patterns": [ | ||
{ | ||
"space": null, | ||
"url_pattern": "https://www.mysite1.com/{Lang}/articles/" | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains 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,60 @@ | ||
import { PreviewModels, PreviewResponses } from '../../../lib'; | ||
import * as responseJson from '../fake-responses/preview/fake-modify-preview-configuration.json'; | ||
import { cmLiveClient, getTestClientWithJson, testEnvironmentId } from '../setup'; | ||
|
||
describe('Modify preview configuration', () => { | ||
let response: PreviewResponses.ModifyConfigurationResponse; | ||
|
||
beforeAll(async () => { | ||
response = await getTestClientWithJson(responseJson) | ||
.modifyPreviewConfiguration() | ||
.withData({ | ||
space_domains: [ | ||
{ | ||
domain: 'z.com', | ||
space: { | ||
codename: 'spaceCodename' | ||
} | ||
} | ||
], | ||
preview_url_patterns: [ | ||
{ | ||
content_type: { | ||
codename: 'contentTypeCodename' | ||
}, | ||
url_patterns: [ | ||
{ | ||
space: { | ||
codename: 'spaceCodename' | ||
}, | ||
url_pattern: 'https://{Space}/{Lang}/articles/history/' | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
.toPromise(); | ||
}); | ||
|
||
it(`url should be correct`, () => { | ||
const url = cmLiveClient | ||
.modifyPreviewConfiguration() | ||
.withData({} as any) | ||
.getUrl(); | ||
|
||
expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/preview-configuration`); | ||
}); | ||
|
||
it(`response should be instance of PreviewResponses.ModifyConfigurationResponse class`, () => { | ||
expect(response).toEqual(jasmine.any(PreviewResponses.ModifyConfigurationResponse)); | ||
}); | ||
|
||
it(`response should contain debug data`, () => { | ||
expect(response.debug).toBeDefined(); | ||
}); | ||
|
||
it(`response should contain data`, () => { | ||
expect(response.data).toBeDefined(); | ||
expect(response.data).toEqual(jasmine.any(PreviewModels.PreviewConfiguration)); | ||
}); | ||
}); |