Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,23 @@ export class Report extends embed.Embed implements IReportNode, IFilterable {
});
}

/**
* Refreshes data sources for report.
*
* ```javascript
* report.refresh();
* ```
*/
refresh(): Promise<void> {
return this.service.hpm.post<models.IError[]>('/report/refresh', null, { uid: this.config.uniqueId }, this.iframe.contentWindow)
.then(response => {
return response.body;
})
.catch(response => {
throw response.body;
});
}

/**
* Remove all filters at report level
*
Expand Down
68 changes: 68 additions & 0 deletions test/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,26 @@ describe('Protocol', function () {
});
});

describe('refresh', function () {
it('POST /report/refresh returns 202 if the request is valid', function (done) {
// Arrange
iframeLoaded
.then(() => {
spyApp.refreshData.and.returnValue(Promise.resolve(null));
// Act
hpm.post<void>('/report/refresh', null)
.then(response => {
// Assert
expect(spyApp.refreshData).toHaveBeenCalled();
expect(response.statusCode).toEqual(202);
// Cleanup
spyApp.refreshData.calls.reset();
done();
});
});
});
});

describe('filters (report level)', function () {
it('GET /report/filters returns 200 with body as array of filters', function (done) {
// Arrange
Expand Down Expand Up @@ -2076,6 +2096,36 @@ describe('SDK-to-HPM', function () {
});
});

describe('refresh', function () {
it('report.refresh() sends POST /report/refresh', function () {
// Arrange
spyHpm.post.and.returnValue(Promise.resolve({
body: {}
}));

// Act
report.refresh();

// Assert
expect(spyHpm.post).toHaveBeenCalledWith('/report/refresh', null, { uid: uniqueId }, iframe.contentWindow);
});

it('report.refresh() returns promise that resolves if the request is accepted', function (done) {
// Arrange
spyHpm.post.and.returnValue(Promise.resolve({
body: {}
}));

// Act
report.refresh()
.then(() => {
// Assert
expect(spyHpm.post).toHaveBeenCalledWith('/report/refresh', null, { uid: uniqueId }, iframe.contentWindow);
done();
});
});
});

describe('settings', function () {
it('report.updateSettings(settings) sends PATCH /report/settings with settings object', function () {
// Arrange
Expand Down Expand Up @@ -3132,6 +3182,24 @@ describe('SDK-to-MockApp', function () {
});
});

describe('refresh', function () {
it('report.refresh() returns promise that resolves with null if the report refresh command was accepted', function (done) {
// Arrange
iframeLoaded
.then(() => {
spyApp.refreshData.and.returnValue(Promise.resolve(null));
// Act
report.refresh()
.then(response => {
// Assert
expect(spyApp.refreshData).toHaveBeenCalled();
expect(response).toEqual(undefined);
done();
});
});
});
});

describe('settings', function () {
it('report.updateSettings(setting) returns promise that rejects with validation error if object is invalid', function (done) {
// Arrange
Expand Down
3 changes: 3 additions & 0 deletions test/utility/mockApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface IApp {
validateFilter(filter: models.IFilter): Promise<models.IError[]>;
// Other
print(): Promise<void>;
refreshData(): Promise<void>;
exportData(): Promise<void>;
}

Expand All @@ -43,6 +44,7 @@ export const mockAppSpyObj = {
validateFilter: jasmine.createSpy("validateFilter").and.callFake(models.validateFilter),
// Other
print: jasmine.createSpy("print").and.returnValue(Promise.resolve(null)),
refreshData: jasmine.createSpy("refreshData").and.returnValue(Promise.resolve(null)),
exportData: jasmine.createSpy("exportData").and.returnValue(Promise.resolve(null)),

reset() {
Expand All @@ -59,6 +61,7 @@ export const mockAppSpyObj = {
mockAppSpyObj.setFilters.calls.reset();
mockAppSpyObj.validateFilter.calls.reset();
mockAppSpyObj.print.calls.reset();
mockAppSpyObj.refreshData.calls.reset();
mockAppSpyObj.exportData.calls.reset();
}
};
Expand Down
5 changes: 5 additions & 0 deletions test/utility/mockReportEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ export function setupMockApp(iframeContentWindow: Window, parentWindow: Window,
});
});

router.post('/report/refresh', (req, res) => {
app.refreshData();
res.send(202);
});

router.patch('/report/settings', (req, res) => {
const uniqueId = req.headers['uid'];
const settings = req.body;
Expand Down