Export option for teams report useractivityuserdetail [options]#1061
Conversation
VelinGeorgiev
left a comment
There was a problem hiding this comment.
@sprider , the tests are failing.
I have added some initial comments for you. Thanks for looking into this.
| `-p, --period <period>`|The length of time over which the report is aggregated. Supported values `D7, D30, D90, D180`. Specify the `period` or `date`, but not both. | ||
| `-d, --date [date]`|The date for which you would like to view the users who performed any activity. Supported date format is `YYYY-MM-DD`. Specify the `date` or `period`, but not both. | ||
| `-f, --outputFile [outputFile]`|Path to the file where the upgrade report should be stored in. | ||
| `-o, --output [output]`|Output type. `csv|json|text`. Default `csv` |
There was a problem hiding this comment.
The output option is there for every command and by default is text. I would suggest you keep it the same as the rest of the commands where it defaults to text and the options are in the following order text,json,csv. See how Waldek did it here: https://github.com/pnp/office365-cli/pull/1037/files
There was a problem hiding this comment.
I have fixed this in the latest commit.
| period?: string; | ||
| date?: string; | ||
| outputFile?: string; | ||
| output?: string; |
There was a problem hiding this comment.
There is no need to introduce new output option since it is already introduced by the parent class, you just have to reuse it. See https://github.com/pnp/office365-cli/pull/1037/files
There was a problem hiding this comment.
I have fixed this in the latest commit.
| telemetryProps.period = typeof args.options.period !== 'undefined'; | ||
| telemetryProps.date = typeof args.options.date !== 'undefined'; | ||
| telemetryProps.outputFile = typeof args.options.outputFile !== 'undefined'; | ||
| telemetryProps.output = typeof args.options.output !== 'undefined'; |
There was a problem hiding this comment.
There is no need to log telemetry for output since it is already captured by the parent class. See https://github.com/pnp/office365-cli/pull/1037/files
There was a problem hiding this comment.
I have fixed this in the latest commit.
|
|
||
| let content: string = ''; | ||
|
|
||
| if (args.options.outputFile.toLowerCase().endsWith('.json')) |
There was a problem hiding this comment.
You should check if the --output option is set to json instead of checking for extension.
There was a problem hiding this comment.
I have fixed this in the latest commit. Just an FYI here user can export the report data to the specified path in csv,txt and json formats
| .then((res: any): void => { | ||
| cmd.log(res); | ||
|
|
||
| if (args.options.outputFile) { |
There was a problem hiding this comment.
The --outputFile check should come after checking the --output option. We should be able to print json on the screen in case of json being specified in the --output and not --outputFile specified. We should be also able to save that json to a file in case --outputFile and --outputFile is specified as well. Something similar is done by Waldek here: https://github.com/pnp/office365-cli/pull/1037/files
There was a problem hiding this comment.
I have fixed this in the latest commit. Just an FYI here user can export the report data to the specified path in csv,txt and json formats
| return 'Specified outputFile path where to save the file does not exist'; | ||
| } | ||
|
|
||
| if (args.options.outputFile && args.options.output && args.options.output.toLowerCase() === 'csv' && !args.options.outputFile.toLowerCase().endsWith('.csv')) { |
There was a problem hiding this comment.
I do not think the extension matters as long as the have --output option specified.
There was a problem hiding this comment.
I have fixed this in the latest commit but do we need to validate the below scenario where output is csv and path ends with json
teams report useractivityuserdetail --period D7 --output csv --outputFile '/Users/josephvelliah/Desktop/teams-report-useractivityuserdetail.json'
There was a problem hiding this comment.
My opinion is that we do not have to validate the extension nor the name for the specified file. The user can name it whatever, he/she will get content in json format when the --output option is set to json.
There was a problem hiding this comment.
Sure, Thank you for the clarification.
| return 'Specified outputFile path should be csv file extension'; | ||
| } | ||
|
|
||
| if (args.options.outputFile && args.options.output && args.options.output.toLowerCase() === 'json' && !args.options.outputFile.toLowerCase().endsWith('.json')) { |
There was a problem hiding this comment.
I do not think the extension matters as long as the have --output option specified.
There was a problem hiding this comment.
I have fixed this in the latest commit but do we need to validate the below scenario where output is csv and path ends with json
teams report useractivityuserdetail --period D7 --output csv --outputFile '/Users/josephvelliah/Desktop/teams-report-useractivityuserdetail.json'
There was a problem hiding this comment.
My opinion is that we do not have to validate the extension nor the name for the specified file. The user can name it whatever, he/she will get content in json format when the --output option is set to json.
There was a problem hiding this comment.
Sure, Thank you for the clarification.
| return 'Specified outputFile path should be json file extension'; | ||
| } | ||
|
|
||
| if (args.options.outputFile && args.options.output && args.options.output.toLowerCase() === 'text' && !args.options.outputFile.toLowerCase().endsWith('.txt')) { |
There was a problem hiding this comment.
I do not think the extension matters as long as the have --output option specified.
There was a problem hiding this comment.
I have fixed this in the latest commit but do we need to validate the below scenario where output is csv and path ends with json
teams report useractivityuserdetail --period D7 --output csv --outputFile '/Users/josephvelliah/Desktop/teams-report-useractivityuserdetail.json'
| for July 13, 2019 | ||
| ${commands.TEAMS_REPORT_USERACTIVITYUSERDETAIL} --date 2019-07-13 | ||
|
|
||
| Gets details about Microsoft Teams user activity by user for the last week and exports the report data in the specified path in csv format |
There was a problem hiding this comment.
Seems like you've build functionality for json output/export, but your example is with csv. Could you please align?
There was a problem hiding this comment.
I have fixed this in the latest commit.
| Gets details about Microsoft Teams user activity by user for the last week and exports the report data in the specified path in csv format | ||
|
|
||
| ```sh | ||
| teams report useractivityuserdetail --period D7 --outputFile '/Users/josephvelliah/Desktop/teams-report-useractivityuserdetail.csv' |
There was a problem hiding this comment.
Seems like you've build functionality for json output/export, but your example is with csv. Could you please align?
There was a problem hiding this comment.
I have fixed this in the latest commit.
|
@VelinGeorgiev |
|
Joseph you will have to do a test with at least two rows of data to cover those lines |
@VelinGeorgiev Sure, this is done. |
|
@VelinGeorgiev My local npm test shows 100%. Do I need to modify anything? |
|
Seems line 74 fails on the build machine. https://circleci.com/gh/pnp/office365-cli/2409?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link. You can do |
@VelinGeorgiev If I am not wrong, circleci is trying to find the path "/Users/josephvelliah/Desktop" to save the file Please let me know how to proceed or mock this. |
|
Joseph @sprider , to fix that you should fake the Have a look how Waldek did it and you can try to do it the same way. |
@VelinGeorgiev I have fixed the issues as per your suggestion. Could you please review and merge this? Thank you. |
VelinGeorgiev
left a comment
There was a problem hiding this comment.
@sprider very well done! I tested the command and everything worked. This is the branch from where we will merge it.
I had to make some cosmetic changes. You can find my comments above.
| if(args.options.outputFile) | ||
| { | ||
| fs.writeFileSync(args.options.outputFile, content, 'binary'); | ||
| cmd.log(`File saved to path '${args.options.outputFile}'`); |
There was a problem hiding this comment.
I added extra condition so that message will show in verbose mode only so the code looks like:
if (this.verbose) {
cmd.log(`File saved to path '${args.options.outputFile}'`);
}
This follows the same pattern we have in other commands like file-get
| { | ||
| let reportdata = this.getJsonReport(res); | ||
| content = JSON.stringify(reportdata); | ||
| cmd.log(reportdata); |
There was a problem hiding this comment.
I added extra condition so that log should show in case user has not specified outputFile so the code looks like:
if (!args.options.outputFile) {
cmd.log(reportdata);
}
This follows the same pattern we have in other commands like file-get where no output on the screen is shown, but just file is generated.
| ${commands.TEAMS_REPORT_USERACTIVITYUSERDETAIL} --date 2019-07-13 | ||
|
|
||
| Gets details about Microsoft Teams user activity by user for the last week and exports the report data in the specified path in json format | ||
| ${commands.TEAMS_REPORT_USERACTIVITYUSERDETAIL} --period D7 --output json --outputFile '/Users/josephvelliah/Desktop/teams-report-useractivityuserdetail.json' |
There was a problem hiding this comment.
/Users/josephvelliah/Desktop/teams-report-useractivityuserdetail.json changed to C:/report.json to shorten the message for smaller screens.
|
|
||
| if(args.options.outputFile) | ||
| { | ||
| fs.writeFileSync(args.options.outputFile, content, 'binary'); |
| else | ||
| { | ||
| content = res; | ||
| cmd.log(content); |
There was a problem hiding this comment.
I added extra condition so that log should show in case user has not specified outputFile so the code looks like:
if (!args.options.outputFile) {
cmd.log(content);
}
This follows the same pattern we have in other commands like file-get where no output on the screen is shown, but just file is generated.
| Gets details about Microsoft Teams user activity by user | ||
| for July 13, 2019 | ||
| ${commands.TEAMS_REPORT_USERACTIVITYUSERDETAIL} --date 2019-07-13 | ||
|
|
There was a problem hiding this comment.
I added another example showing how to export in csv as well
Gets details about Microsoft Teams user activity by user for the last week
and exports the report data in the specified path in csv format
${commands.TEAMS_REPORT_USERACTIVITYUSERDETAIL} --period D7 --output csv --outputFile 'C:/report.csv'
|
|
||
| return Promise.reject('Invalid request'); | ||
| }); | ||
| sinon.stub(fs, 'writeFileSync').callsFake(writeFileSyncFake); |
There was a problem hiding this comment.
I assigned that stub to a var so I can tested later like
const fileStub: sinon.SinonStub = sinon.stub(fs, 'writeFileSync').callsFake(writeFileSyncFake);
| assert.equal(requestStub.lastCall.args[0].headers["accept"], 'application/json;odata.metadata=none'); | ||
| assert.equal(requestStub.lastCall.args[0].json, true); | ||
| assert(cmdInstanceLogSpy.calledWith(`File saved to path '/Users/josephvelliah/Desktop/teams-report-useractivityuserdetail.json'`)); | ||
| done(); |
There was a problem hiding this comment.
I added extra assets to check if the writeFileSync is actually been called. This will verify that file will be created.
assert.equal(fileStub.called, true);
|
Thank you Jospeh @sprider ! Merged manually 🚀 |
Thank you for your guidance @VelinGeorgiev. I will implement the same in other teams report related commands. |




@VelinGeorgiev,
I have completed the export logic based on the comments provided by you at issue #1038.
Let us start the review and I can work on your feedbacks in parallel. Also I will work on code coverage items at teams-report-useractivityuserdetail.spec.ts file once we finish the review for teams-report-useractivityuserdetail.ts and report-useractivityuserdetail.md files.
Thank you.