1 | var expect = require('chai').expect;
|
2 |
|
3 | const AWSUtility = require('../utils/AWSS3Utils');
|
4 |
|
5 | describe("AWSUtility Testing", function () {
|
6 |
|
7 |
|
8 | it('should get s3 file content', async function () {
|
9 |
|
10 |
|
11 | return AWSUtility.getS3File('hpgimages', 'hello.html')
|
12 | .then((file)=>{
|
13 | expect(file).to.be.a('string');
|
14 | })
|
15 |
|
16 |
|
17 |
|
18 | }),
|
19 | it('should get error in case of undefined bucket name', async function () {
|
20 | var file = await AWSUtility.getS3File(undefined, 'hello.html')
|
21 | .then((file)=>{
|
22 | console.log('test')
|
23 | })
|
24 | .catch(function (error) {
|
25 | expect(function () { throw error }).to.throw(Error, 'bucket name is invalid');
|
26 | });
|
27 | }),
|
28 | it('should get error in case of undefined bucket name', async function () {
|
29 | AWSUtility.getS3File('hpgimages', undefined)
|
30 | .catch(function (error) {
|
31 | expect(function () { throw error })
|
32 | .to.throw(Error, 'file name is invalid');
|
33 | });
|
34 | }),
|
35 | it('should get error in case of invalid bucket name', async function () {
|
36 | AWSUtility.getS3File('hpgimageds', 'hhgh')
|
37 | .catch(function (error) {
|
38 | expect(function () { throw error })
|
39 | .to.throw(Error, 'The specified bucket does not exist');
|
40 | });
|
41 | }),
|
42 | it('should get error in case of invalid file name', async function () {
|
43 | await AWSUtility.getS3File('hpgimages', 'hhgh')
|
44 | .catch(function (error) {
|
45 | expect(function () { throw error })
|
46 | .to.throw(Error, 'The specified key does not exist');
|
47 | });
|
48 | }),
|
49 | it('should upload content to s3 - put', async function () {
|
50 | var file = await AWSUtility.getS3File('hpgimages', 'hello.html');
|
51 | AWSUtility.putS3File('hpgimages', 'testput.html',file)
|
52 | .then((response)=>{
|
53 | console.log('response - '+ response)
|
54 | expect(response).to.be.a('string')
|
55 | })
|
56 |
|
57 | }),
|
58 | it('should get error in case of undefined bucket name - put', async function () {
|
59 | var file = await AWSUtility.getS3File('hpgimages', 'hello.html');
|
60 | await AWSUtility.putS3File(undefined,'hpgimages',file)
|
61 | .catch(function (error) {
|
62 | expect(function () { throw error })
|
63 | .to.throw(Error, 'bucket name is invalid');
|
64 | });
|
65 | }),
|
66 | it('should get error in case of undefined file name - put', async function () {
|
67 | var file = await AWSUtility.getS3File('hpgimages', 'hello.html');
|
68 | await AWSUtility.putS3File('hpgimages', undefined,file)
|
69 |
|
70 | .catch(function (error) {
|
71 | expect(function () { throw error })
|
72 | .to.throw(Error, 'file name is invalid');
|
73 | });
|
74 | }),
|
75 | it('should get error in case of invalid file name - put', async function () {
|
76 | var file = await AWSUtility.getS3File('hpgimages', 'hello.html');
|
77 | AWSUtility.putS3File('hpgimages', 'ooo', undefined)
|
78 | .catch(function (error) {
|
79 | expect(function () { throw error })
|
80 | .to.throw(Error, 'content is invalid');
|
81 | });
|
82 | }),
|
83 | it('should get error in case of invalid bucket name - put', async function () {
|
84 | var file = await AWSUtility.getS3File('hpgimages', 'hello.html');
|
85 | await AWSUtility.putS3File('xyz', 'hello.html', file)
|
86 | .catch(function (error) {
|
87 | expect(function () { throw error })
|
88 | .to.throw(Error, 'The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.');
|
89 | })
|
90 |
|
91 | })
|
92 | })
|
93 |
|
94 |
|