1 | import test from "ava";
|
2 | import Chance from "../chance.js";
|
3 | import _ from "lodash";
|
4 |
|
5 | const chance = new Chance();
|
6 |
|
7 | test("fileWithContent() returns a random filename but extention of .gif", (t) => {
|
8 | _.times(1, () => {
|
9 | const file = chance.fileWithContent({
|
10 | fileExtension: "gif",
|
11 | fileSize: 1024,
|
12 | });
|
13 | t.true(_.isBuffer(file.fileData));
|
14 | t.is(file.fileName.split(".")[1], "gif");
|
15 | });
|
16 | });
|
17 |
|
18 | test("fileWithContent() returns a file with a distinct name", (t) => {
|
19 | _.times(1, () => {
|
20 | const file = chance.fileWithContent({
|
21 | fileSize: 2048,
|
22 | fileName: "coolFileName",
|
23 | });
|
24 | t.is(file.fileName.split(".")[0], "coolFileName");
|
25 | });
|
26 | });
|
27 |
|
28 | test("fileWithContent() returns a file of distinct size", (t) => {
|
29 | _.times(1, () => {
|
30 | const file = chance.fileWithContent({ fileSize: 2048 });
|
31 | t.is(file.fileData.length, 2048);
|
32 | });
|
33 | });
|
34 |
|
35 | test("fileWithContent() throws if fileSize is missing", (t) => {
|
36 | _.times(1, () => {
|
37 | const fn = () => chance.fileWithContent({});
|
38 | t.throws(fn, "File size must be an integer");
|
39 | });
|
40 | });
|
41 |
|
42 | test("fileWithContent() throws if bad fileSize options is provided", (t) => {
|
43 | _.times(1, () => {
|
44 | const fn = () => chance.fileWithContent({ fileSize: "Large" });
|
45 | t.throws(fn, "File size must be an integer");
|
46 | });
|
47 | });
|
48 |
|
49 | test("fileWithContent() throws if bad fileSize is less than 0", (t) => {
|
50 | _.times(1, () => {
|
51 | const fn = () => chance.fileWithContent({ fileSize: -1 });
|
52 | t.throws(fn, "Chance: Length cannot be less than zero.");
|
53 | });
|
54 | });
|