Fix comparing MB -> bytes

pull/21833/head
Jaiwanth 2021-08-03 14:53:23 +05:30
parent 4824c93707
commit b333612dea
2 changed files with 31 additions and 22 deletions

View File

@ -42,7 +42,9 @@ export default abstract class Exporter {
protected exportOptions: IExportOptions,
protected exportProgressRef: MutableRefObject<HTMLParagraphElement>,
) {
if (exportOptions.maxSize < 1 || exportOptions.maxSize > 2000 || exportOptions.numberOfMessages > 10**8) {
if (exportOptions.maxSize < 1 * 1024 * 1024||
exportOptions.maxSize > 2000 * 1024 * 1024||
exportOptions.numberOfMessages > 10**8) {
throw new Error("Invalid export options");
}
this.cancelled = false;

View File

@ -16,9 +16,9 @@ limitations under the License.
import { MatrixClient, Room } from "matrix-js-sdk";
import { MatrixClientPeg } from "../../src/MatrixClientPeg";
import { textForFormat } from "../../src/utils/exportUtils/exportUtils";
// import HTMLExporter from "../../src/utils/exportUtils/HtmlExport";
// import PlainTextExporter from "../../src/utils/exportUtils/PlainTextExport";
import { textForFormat, IExportOptions, ExportTypes } from "../../src/utils/exportUtils/exportUtils";
import '../skinned-sdk';
import PlainTextExporter from "../../src/utils/exportUtils/PlainTextExport";
import * as TestUtilsMatrix from '../test-utils';
import { stubClient } from '../test-utils';
@ -37,23 +37,23 @@ describe('export', function() {
return MY_USER_ID;
};
// const invalidExportOptions: IExportOptions[] = [
// {
// numberOfMessages: 10**9,
// maxSize: 1024,
// attachmentsIncluded: false,
// },
// {
// numberOfMessages: -1,
// maxSize: 4096,
// attachmentsIncluded: false,
// },
// {
// numberOfMessages: 0,
// maxSize: 1024,
// attachmentsIncluded: false,
// },
// ];
const invalidExportOptions: IExportOptions[] = [
{
numberOfMessages: 10**9,
maxSize: 1024 * 1024 * 1024,
attachmentsIncluded: false,
},
{
numberOfMessages: -1,
maxSize: 4096 * 1024 * 1024,
attachmentsIncluded: false,
},
{
numberOfMessages: 0,
maxSize: 0,
attachmentsIncluded: false,
},
];
const events = mkEvents();
const room = createRoom();
@ -88,7 +88,14 @@ describe('export', function() {
});
it('checks if the export options are valid', function() {
// const html = new PlainTextExporter(room, ExportTypes.BEGINNING, invalidExportOptions[0], null);
for (const exportOption of invalidExportOptions) {
try {
new PlainTextExporter(room, ExportTypes.BEGINNING, exportOption, null);
throw new Error("Expected to throw an error");
} catch (e) {
expect(e.message).toBe("Invalid export options");
}
}
});
});