index.test.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { describe, expect, it } from '@jest/globals'
  2. import 'whatwg-fetch'
  3. import Core from '@uppy/core'
  4. import AwsS3 from './index.js'
  5. describe('AwsS3', () => {
  6. it('Registers AwsS3 upload plugin', () => {
  7. const core = new Core()
  8. core.use(AwsS3)
  9. const pluginNames = core[Symbol.for('uppy test: getPlugins')]('uploader').map((plugin) => plugin.constructor.name)
  10. expect(pluginNames).toContain('AwsS3')
  11. })
  12. describe('getUploadParameters', () => {
  13. it('Throws an error if configured without companionUrl', () => {
  14. const core = new Core()
  15. core.use(AwsS3)
  16. const awsS3 = core.getPlugin('AwsS3')
  17. expect(awsS3.opts.getUploadParameters).toThrow()
  18. })
  19. it('Does not throw an error with companionUrl configured', () => {
  20. const core = new Core()
  21. core.use(AwsS3, { companionUrl: 'https://uppy-companion.myapp.com/' })
  22. const awsS3 = core.getPlugin('AwsS3')
  23. const file = {
  24. meta: {
  25. name: 'foo.jpg',
  26. type: 'image/jpg',
  27. },
  28. }
  29. expect(() => awsS3.opts.getUploadParameters(file)).not.toThrow()
  30. })
  31. })
  32. describe('dynamic companionHeader', () => {
  33. let core
  34. let awsS3
  35. const oldToken = 'old token'
  36. const newToken = 'new token'
  37. beforeEach(() => {
  38. core = new Core()
  39. core.use(AwsS3, {
  40. companionHeaders: {
  41. authorization: oldToken,
  42. },
  43. })
  44. awsS3 = core.getPlugin('AwsS3')
  45. })
  46. it('companionHeader is updated before uploading file', async () => {
  47. awsS3.setOptions({
  48. companionHeaders: {
  49. authorization: newToken,
  50. },
  51. })
  52. await core.upload()
  53. const client = awsS3[Symbol.for('uppy test: getClient')]()
  54. expect(client[Symbol.for('uppy test: getCompanionHeaders')]().authorization).toEqual(newToken)
  55. })
  56. })
  57. })