|
1 | 1 | // Define globals for eslint.
|
2 |
| -/* global describe it jest */ |
| 2 | +/* global describe it */ |
3 | 3 |
|
4 | 4 | // Load dependencies
|
5 | 5 | import should from 'should'; // eslint-disable-line no-unused-vars
|
@@ -121,75 +121,35 @@ describe('FileSystem', function () {
|
121 | 121 | pngFilenameTwo.should.equal('09091b8880ddb982968a0fe28abed5034f9a43b8.png');
|
122 | 122 | });
|
123 | 123 |
|
124 |
| - it('#getFileNameFromUrl should handle PNG/JPG/GIF/BMP urls without file extensions by using content-type header.', async () => { |
| 124 | + it('#getFileNameFromUrl should handle PNG/JPG/GIF/BMP urls and urls without file extensions.', async () => { |
125 | 125 | const fileSystem = FileSystemFactory();
|
126 | 126 |
|
127 |
| - // Mock fetch |
128 |
| - fetch = jest.fn(); // eslint-disable-line no-global-assign |
129 |
| - |
130 |
| - // Test PNG |
131 |
| - fetch.mockResolvedValueOnce({ |
132 |
| - headers: { |
133 |
| - get: (headerName) => { |
134 |
| - headerName.should.equals('content-type'); |
135 |
| - |
136 |
| - return 'image/png'; |
137 |
| - }, |
138 |
| - }, |
139 |
| - }); |
140 |
| - |
141 | 127 | const pngFilename = await fileSystem.getFileNameFromUrl(
|
142 |
| - 'https://cdn2.hubspot.net/hub/42284/file-14233687-jpg/images/test_in_red' |
| 128 | + 'https://cdn2.hubspot.net/hub/42284/file-14233687-jpg/images/test_in_red.png' |
143 | 129 | );
|
144 |
| - pngFilename.should.equal('831eb245a3d9032cdce450f8760d2b8ddb442a3d.png'); |
145 |
| - |
146 |
| - // Test JPG |
147 |
| - fetch.mockResolvedValueOnce({ |
148 |
| - headers: { |
149 |
| - get: (headerName) => { |
150 |
| - headerName.should.equals('content-type'); |
151 |
| - |
152 |
| - return 'image/jpeg'; |
153 |
| - }, |
154 |
| - }, |
155 |
| - }); |
| 130 | + pngFilename.should.equal('b89a6739cdfd993a9b5d43b2ff4aa216e17c63ae.png'); |
156 | 131 |
|
157 | 132 | const jpgFilename = await fileSystem.getFileNameFromUrl(
|
158 |
| - 'https://cdn2.hubspot.net/hub/42284/file-14233687-jpg/images/test_in_red' |
| 133 | + 'https://cdn2.hubspot.net/hub/42284/file-14233687-jpg/images/test_in_red.jpg' |
159 | 134 | );
|
160 |
| - jpgFilename.should.equal('831eb245a3d9032cdce450f8760d2b8ddb442a3d.jpg'); |
161 |
| - |
162 |
| - // Test GIF |
163 |
| - fetch.mockResolvedValueOnce({ |
164 |
| - headers: { |
165 |
| - get: (headerName) => { |
166 |
| - headerName.should.equals('content-type'); |
167 |
| - |
168 |
| - return 'image/gif'; |
169 |
| - }, |
170 |
| - }, |
171 |
| - }); |
| 135 | + jpgFilename.should.equal('6adf4569ecc3bf8c378bb4d47b1995cd85c5a13c.jpg'); |
172 | 136 |
|
173 | 137 | const gifFilename = await fileSystem.getFileNameFromUrl(
|
174 |
| - 'https://cdn2.hubspot.net/hub/42284/file-14233687-jpg/images/test_in_red' |
| 138 | + 'https://cdn2.hubspot.net/hub/42284/file-14233687-jpg/images/test_in_red.gif' |
175 | 139 | );
|
176 |
| - gifFilename.should.equal('831eb245a3d9032cdce450f8760d2b8ddb442a3d.gif'); |
177 |
| - |
178 |
| - // Test BMP |
179 |
| - fetch.mockResolvedValueOnce({ |
180 |
| - headers: { |
181 |
| - get: (headerName) => { |
182 |
| - headerName.should.equals('content-type'); |
183 |
| - |
184 |
| - return 'image/bmp'; |
185 |
| - }, |
186 |
| - }, |
187 |
| - }); |
| 140 | + gifFilename.should.equal('f0bc1d93ca75e6e355188391e3d0f1aab6d30bad.gif'); |
188 | 141 |
|
189 | 142 | const bmpFilename = await fileSystem.getFileNameFromUrl(
|
| 143 | + 'https://cdn2.hubspot.net/hub/42284/file-14233687-jpg/images/test_in_red.bmp' |
| 144 | + ); |
| 145 | + bmpFilename.should.equal('ca15f1856605a6a5ca1d426a12f91efdc061b31c.bmp'); |
| 146 | + |
| 147 | + const unknownFilename = await fileSystem.getFileNameFromUrl( |
190 | 148 | 'https://cdn2.hubspot.net/hub/42284/file-14233687-jpg/images/test_in_red'
|
191 | 149 | );
|
192 |
| - bmpFilename.should.equal('831eb245a3d9032cdce450f8760d2b8ddb442a3d.bmp'); |
| 150 | + unknownFilename.should.equal( |
| 151 | + '831eb245a3d9032cdce450f8760d2b8ddb442a3d.bin' |
| 152 | + ); |
193 | 153 | });
|
194 | 154 |
|
195 | 155 | it('#getLocalFilePathFromUrl should return local filepath if it exists on local fs in permanent dir.', () => {
|
|
0 commit comments