|
| 1 | +const assert = require('assert'); |
| 2 | +const hook = require('../../../src/custom/cappasity-upload-pre'); |
| 3 | +const reject = require('lodash/reject'); |
| 4 | +const { inspectPromise } = require('../../helpers/utils'); |
| 5 | + |
| 6 | +describe('cappasity-upload-pre hook test suite', function suite() { |
| 7 | + describe('validate model files', function modelSuite() { |
| 8 | + const data = { |
| 9 | + files: [{ |
| 10 | + type: 'c-bin', |
| 11 | + }, { |
| 12 | + type: 'c-texture', |
| 13 | + }, { |
| 14 | + type: 'c-archive', |
| 15 | + }], |
| 16 | + meta: {}, |
| 17 | + }; |
| 18 | + |
| 19 | + it('should pass', function test() { |
| 20 | + return hook(data) |
| 21 | + .reflect() |
| 22 | + .then(inspectPromise()); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should fail due to no c-bin files passed', function test() { |
| 26 | + const payload = { |
| 27 | + ...data, |
| 28 | + files: reject(data.files, { type: 'c-bin' }), |
| 29 | + }; |
| 30 | + |
| 31 | + return hook(payload) |
| 32 | + .reflect() |
| 33 | + .then(inspectPromise(false)); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should fail due to no temp flag passed along with export flag', function test() { |
| 37 | + const payload = { |
| 38 | + ...data, |
| 39 | + meta: { |
| 40 | + export: true, |
| 41 | + }, |
| 42 | + }; |
| 43 | + |
| 44 | + return hook(payload) |
| 45 | + .reflect() |
| 46 | + .then(inspectPromise(false)); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should fail when several c-bin files are passed', function test() { |
| 50 | + const payload = { |
| 51 | + ...data, |
| 52 | + files: [{ |
| 53 | + type: 'c-bin', |
| 54 | + }, { |
| 55 | + type: 'c-bin', |
| 56 | + }], |
| 57 | + }; |
| 58 | + |
| 59 | + return hook(payload) |
| 60 | + .reflect() |
| 61 | + .then(inspectPromise(false)); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should pass when both flags `export` and `temp` are passed', function test() { |
| 65 | + const payload = { |
| 66 | + ...data, |
| 67 | + export: true, |
| 68 | + temp: true, |
| 69 | + }; |
| 70 | + |
| 71 | + return hook(payload) |
| 72 | + .reflect() |
| 73 | + .then(inspectPromise()); |
| 74 | + }); |
| 75 | + }); |
| 76 | + |
| 77 | + describe('validate non-model files', function nonModelSuite() { |
| 78 | + const data = { |
| 79 | + files: [{ |
| 80 | + type: 'c-preview', |
| 81 | + }], |
| 82 | + access: { |
| 83 | + setPublic: true, |
| 84 | + }, |
| 85 | + unlisted: true, |
| 86 | + }; |
| 87 | + |
| 88 | + it('should pass for cappasity preview', function test() { |
| 89 | + return hook(data) |
| 90 | + .reflect() |
| 91 | + .then(inspectPromise()); |
| 92 | + }); |
| 93 | + |
| 94 | + it('should pass for background image', function test() { |
| 95 | + const payload = { |
| 96 | + ...data, |
| 97 | + files: [{ |
| 98 | + type: 'background', |
| 99 | + }], |
| 100 | + }; |
| 101 | + |
| 102 | + return hook(payload) |
| 103 | + .reflect() |
| 104 | + .then(inspectPromise()); |
| 105 | + }); |
| 106 | + |
| 107 | + it('should fail when passed a single non-preview, non-background file', function test() { |
| 108 | + const payload = { |
| 109 | + ...data, |
| 110 | + files: [{ |
| 111 | + type: 'c-bin', |
| 112 | + }], |
| 113 | + }; |
| 114 | + |
| 115 | + return hook(payload) |
| 116 | + .reflect() |
| 117 | + .then(inspectPromise(false)); |
| 118 | + }); |
| 119 | + |
| 120 | + it('should fail when file is private', function test() { |
| 121 | + const payload = { |
| 122 | + ...data, |
| 123 | + access: { |
| 124 | + setPublic: false, |
| 125 | + }, |
| 126 | + }; |
| 127 | + |
| 128 | + return hook(payload) |
| 129 | + .reflect() |
| 130 | + .then(inspectPromise(false)); |
| 131 | + }); |
| 132 | + |
| 133 | + it('should fail when file is listed', function test() { |
| 134 | + const payload = { |
| 135 | + ...data, |
| 136 | + unlisted: false, |
| 137 | + }; |
| 138 | + |
| 139 | + return hook(payload) |
| 140 | + .reflect() |
| 141 | + .then(inspectPromise(false)); |
| 142 | + }); |
| 143 | + |
| 144 | + it('should fail when several non-model files are passed', function test() { |
| 145 | + const payload = { |
| 146 | + ...data, |
| 147 | + files: [{ |
| 148 | + type: 'background', |
| 149 | + }, { |
| 150 | + type: 'c-preview', |
| 151 | + }], |
| 152 | + }; |
| 153 | + |
| 154 | + return hook(payload) |
| 155 | + .reflect() |
| 156 | + .then(inspectPromise(false)); |
| 157 | + }); |
| 158 | + }); |
| 159 | +}); |
0 commit comments