Skip to content

Commit a43d98a

Browse files
author
Matt Mazzola
authored
Add report.refresh() which refreshes report data. (microsoft#33)
1 parent 389bc12 commit a43d98a

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

src/report.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,23 @@ export class Report extends embed.Embed implements IReportNode, IFilterable {
174174
});
175175
}
176176

177+
/**
178+
* Refreshes data sources for report.
179+
*
180+
* ```javascript
181+
* report.refresh();
182+
* ```
183+
*/
184+
refresh(): Promise<void> {
185+
return this.service.hpm.post<models.IError[]>('/report/refresh', null, { uid: this.config.uniqueId }, this.iframe.contentWindow)
186+
.then(response => {
187+
return response.body;
188+
})
189+
.catch(response => {
190+
throw response.body;
191+
});
192+
}
193+
177194
/**
178195
* Remove all filters at report level
179196
*

test/test.spec.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,26 @@ describe('Protocol', function () {
10371037
});
10381038
});
10391039

1040+
describe('refresh', function () {
1041+
it('POST /report/refresh returns 202 if the request is valid', function (done) {
1042+
// Arrange
1043+
iframeLoaded
1044+
.then(() => {
1045+
spyApp.refreshData.and.returnValue(Promise.resolve(null));
1046+
// Act
1047+
hpm.post<void>('/report/refresh', null)
1048+
.then(response => {
1049+
// Assert
1050+
expect(spyApp.refreshData).toHaveBeenCalled();
1051+
expect(response.statusCode).toEqual(202);
1052+
// Cleanup
1053+
spyApp.refreshData.calls.reset();
1054+
done();
1055+
});
1056+
});
1057+
});
1058+
});
1059+
10401060
describe('filters (report level)', function () {
10411061
it('GET /report/filters returns 200 with body as array of filters', function (done) {
10421062
// Arrange
@@ -2076,6 +2096,36 @@ describe('SDK-to-HPM', function () {
20762096
});
20772097
});
20782098

2099+
describe('refresh', function () {
2100+
it('report.refresh() sends POST /report/refresh', function () {
2101+
// Arrange
2102+
spyHpm.post.and.returnValue(Promise.resolve({
2103+
body: {}
2104+
}));
2105+
2106+
// Act
2107+
report.refresh();
2108+
2109+
// Assert
2110+
expect(spyHpm.post).toHaveBeenCalledWith('/report/refresh', null, { uid: uniqueId }, iframe.contentWindow);
2111+
});
2112+
2113+
it('report.refresh() returns promise that resolves if the request is accepted', function (done) {
2114+
// Arrange
2115+
spyHpm.post.and.returnValue(Promise.resolve({
2116+
body: {}
2117+
}));
2118+
2119+
// Act
2120+
report.refresh()
2121+
.then(() => {
2122+
// Assert
2123+
expect(spyHpm.post).toHaveBeenCalledWith('/report/refresh', null, { uid: uniqueId }, iframe.contentWindow);
2124+
done();
2125+
});
2126+
});
2127+
});
2128+
20792129
describe('settings', function () {
20802130
it('report.updateSettings(settings) sends PATCH /report/settings with settings object', function () {
20812131
// Arrange
@@ -3132,6 +3182,24 @@ describe('SDK-to-MockApp', function () {
31323182
});
31333183
});
31343184

3185+
describe('refresh', function () {
3186+
it('report.refresh() returns promise that resolves with null if the report refresh command was accepted', function (done) {
3187+
// Arrange
3188+
iframeLoaded
3189+
.then(() => {
3190+
spyApp.refreshData.and.returnValue(Promise.resolve(null));
3191+
// Act
3192+
report.refresh()
3193+
.then(response => {
3194+
// Assert
3195+
expect(spyApp.refreshData).toHaveBeenCalled();
3196+
expect(response).toEqual(undefined);
3197+
done();
3198+
});
3199+
});
3200+
});
3201+
});
3202+
31353203
describe('settings', function () {
31363204
it('report.updateSettings(setting) returns promise that rejects with validation error if object is invalid', function (done) {
31373205
// Arrange

test/utility/mockApp.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface IApp {
2020
validateFilter(filter: models.IFilter): Promise<models.IError[]>;
2121
// Other
2222
print(): Promise<void>;
23+
refreshData(): Promise<void>;
2324
exportData(): Promise<void>;
2425
}
2526

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

4850
reset() {
@@ -59,6 +61,7 @@ export const mockAppSpyObj = {
5961
mockAppSpyObj.setFilters.calls.reset();
6062
mockAppSpyObj.validateFilter.calls.reset();
6163
mockAppSpyObj.print.calls.reset();
64+
mockAppSpyObj.refreshData.calls.reset();
6265
mockAppSpyObj.exportData.calls.reset();
6366
}
6467
};

test/utility/mockReportEmbed.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ export function setupMockApp(iframeContentWindow: Window, parentWindow: Window,
240240
});
241241
});
242242

243+
router.post('/report/refresh', (req, res) => {
244+
app.refreshData();
245+
res.send(202);
246+
});
247+
243248
router.patch('/report/settings', (req, res) => {
244249
const uniqueId = req.headers['uid'];
245250
const settings = req.body;

0 commit comments

Comments
 (0)