Skip to content

Commit 6d9d0c6

Browse files
Mohit TejaniMohit Tejani
authored andcommitted
test for web to confirm access to File
1 parent c6dec98 commit 6d9d0c6

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

test/dist/web.test.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* global describe, beforeEach, it, before, afterEach, after, chai */
2+
/* eslint no-console: 0 */
3+
4+
import { expect } from 'chai';
5+
import PubNub from '../../src/web';
6+
7+
var pubnub;
8+
9+
describe('#distribution test (web)', function () {
10+
before(function () {
11+
pubnub = new PubNub({
12+
subscribeKey: 'demo',
13+
publishKey: 'demo',
14+
uuid: 'myUUID',
15+
});
16+
});
17+
18+
after(function () {
19+
pubnub.destroy();
20+
});
21+
22+
describe('#File', function () {
23+
it('should have access to File property on pubnub instance', function () {
24+
expect(pubnub.File).to.be.a('function');
25+
expect(pubnub.File).to.have.property('create');
26+
});
27+
28+
it('should be able to create a PubNubFile using pubnub.File.create() with data object', function () {
29+
var fileData = {
30+
data: 'Hello World',
31+
name: 'test.txt',
32+
mimeType: 'text/plain',
33+
};
34+
35+
var file = pubnub.File.create(fileData);
36+
37+
expect(file).to.be.an('object');
38+
expect(file).to.have.property('name').equal('test.txt');
39+
expect(file).to.have.property('mimeType').equal('text/plain');
40+
expect(file).to.have.property('data');
41+
});
42+
43+
it('should be able to create a PubNubFile using pubnub.File.create() with Blob', function () {
44+
var blob = new Blob(['test content'], { type: 'text/plain' });
45+
var fileData = {
46+
data: blob,
47+
name: 'blob-test.txt',
48+
mimeType: 'text/plain',
49+
};
50+
51+
var file = pubnub.File.create(fileData);
52+
53+
expect(file).to.be.an('object');
54+
expect(file).to.have.property('name').equal('blob-test.txt');
55+
expect(file).to.have.property('mimeType').equal('text/plain');
56+
});
57+
58+
it('should be able to create a PubNubFile using pubnub.File.create() with ArrayBuffer', function () {
59+
var buffer = new ArrayBuffer(8);
60+
var fileData = {
61+
data: buffer,
62+
name: 'buffer-test.bin',
63+
mimeType: 'application/octet-stream',
64+
};
65+
66+
var file = pubnub.File.create(fileData);
67+
68+
expect(file).to.be.an('object');
69+
expect(file).to.have.property('name').equal('buffer-test.bin');
70+
expect(file).to.have.property('mimeType').equal('application/octet-stream');
71+
});
72+
73+
it('should throw error when creating PubNubFile without required parameters', function () {
74+
expect(function () {
75+
pubnub.File.create({});
76+
}).to.throw();
77+
});
78+
});
79+
});

0 commit comments

Comments
 (0)