Skip to content

Commit 6bc5d6d

Browse files
Fixes broken tests in 'tenant auditlog report' on Node@10. Closes #2125
1 parent 7d10020 commit 6bc5d6d

3 files changed

Lines changed: 19 additions & 15 deletions

File tree

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
"build": "tsc -p . && node scripts/copy-files.js",
2222
"watch": "tsc -w -p .",
2323
"clean": "rimraf ./dist",
24-
"test": "c8 mocha \"dist/**/*.spec.js\"",
25-
"test:dev": "c8 mocha \"dist/**/Cli.spec.js\""
24+
"test": "c8 mocha \"dist/**/*.spec.js\""
2625
},
2726
"keywords": [
2827
"office 365",

src/m365/tenant/commands/auditlog/auditlog-report.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,9 @@ describe(commands.TENANT_AUDITLOG_REPORT, () => {
314314
debug: false,
315315
contentType: 'Exchange'
316316
}
317-
} as any, () => {
317+
} as any, (err?: any) => {
318318
try {
319-
assert.strictEqual(loggerLogSpy.args[0][0][0].Id, "fbcdc0c0-035c-43b7-9026-08d89e299188");
319+
assert.strictEqual(typeof err, 'undefined');
320320
done();
321321
}
322322
catch (e) {
@@ -360,9 +360,9 @@ describe(commands.TENANT_AUDITLOG_REPORT, () => {
360360
debug: false,
361361
contentType: 'Exchange'
362362
}
363-
} as any, () => {
363+
} as any, (err?: any) => {
364364
try {
365-
assert.strictEqual(loggerLogSpy.args[0][0][0].Id, "fbcdc0c0-035c-43b7-9026-08d89e299188");
365+
assert.strictEqual(typeof err, 'undefined');
366366
done();
367367
}
368368
catch (e) {
@@ -406,8 +406,9 @@ describe(commands.TENANT_AUDITLOG_REPORT, () => {
406406
debug: true,
407407
contentType: 'Exchange'
408408
}
409-
} as any, () => {
409+
} as any, (err?: any) => {
410410
try {
411+
console.log(err);
411412
assert(loggerLogToStderrSpy.calledWith(chalk.green('DONE')));
412413
done();
413414
}

src/m365/tenant/commands/auditlog/auditlog-report.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ class TenantAuditlogReportCommand extends Command {
9595
return this
9696
.startContentSubscriptionIfNotActive(args, logger)
9797
.then((): Promise<AuditContentList[]> => this.getAuditContentList(args, logger))
98-
.then((auditContentLists: AuditContentList[]): Promise<any> => this.getBatchedPromises(auditContentLists, 10))
99-
.then((batchedPromise: Promise<any>[]): Promise<void> => {
98+
.then((auditContentLists: AuditContentList[]): Promise<Promise<AuditlogReport[]>[][]> => this.getBatchedPromises(auditContentLists, 10))
99+
.then((batchedPromise: Promise<AuditlogReport[]>[][]): Promise<void> => {
100100
return new Promise<void>((resolve: () => void, reject: (err: any) => void): void => {
101101
if (batchedPromise.length > 0) {
102102
this.getBatchedAuditlogData(logger, batchedPromise, 0, resolve, reject);
@@ -106,7 +106,7 @@ class TenantAuditlogReportCommand extends Command {
106106
}
107107
});
108108
})
109-
.then((): AuditlogReport[] => { return this.completeAuditReports.flat(2) });
109+
.then(_ => this.completeAuditReports);
110110
}
111111

112112
private startContentSubscriptionIfNotActive(args: CommandArgs, logger: Logger): Promise<void> {
@@ -181,8 +181,8 @@ class TenantAuditlogReportCommand extends Command {
181181
return request.get<AuditContentList[]>(requestOptions)
182182
}
183183

184-
private getBatchedPromises(auditContentLists: AuditContentList[], batchSize: number): Promise<any> {
185-
let batchedPromises: any = [];
184+
private getBatchedPromises(auditContentLists: AuditContentList[], batchSize: number): Promise<Promise<AuditlogReport[]>[][]> {
185+
const batchedPromises: Promise<AuditlogReport[]>[][] = [];
186186

187187
for (let i: number = 0; i < auditContentLists.length; i += batchSize) {
188188
const promiseRequestBatch: Promise<AuditlogReport[]>[] = auditContentLists
@@ -195,15 +195,19 @@ class TenantAuditlogReportCommand extends Command {
195195
return Promise.resolve(batchedPromises);
196196
}
197197

198-
private getBatchedAuditlogData(logger: Logger, batchedPromiseList: any, batchNumber: number, resolve: () => void, reject: (err: any) => void): void {
198+
private getBatchedAuditlogData(logger: Logger, batchedPromiseList: Promise<AuditlogReport[]>[][], batchNumber: number, resolve: () => void, reject: (err: any) => void): void {
199199
if (this.verbose) {
200200
logger.logToStderr(`Starting Batch : ${batchNumber}`);
201201
}
202202

203203
Promise
204204
.all(batchedPromiseList[batchNumber])
205-
.then((data: any) => {
206-
this.completeAuditReports.push(data);
205+
.then((data: AuditlogReport[][]) => {
206+
data.forEach(d1 => {
207+
d1.forEach(d2 => {
208+
this.completeAuditReports.push(d2);
209+
});
210+
});
207211

208212
if (batchNumber < batchedPromiseList.length - 1) {
209213
this.getBatchedAuditlogData(logger, batchedPromiseList, ++batchNumber, resolve, reject)

0 commit comments

Comments
 (0)