|
| 1 | +const { createComponent } = require('../test-utils') |
| 2 | + |
| 3 | +const { |
| 4 | + mockCreateDistribution, |
| 5 | + mockUpdateDistribution, |
| 6 | + mockCreateDistributionPromise, |
| 7 | + mockGetDistributionConfigPromise, |
| 8 | + mockUpdateDistributionPromise |
| 9 | +} = require('aws-sdk') |
| 10 | + |
| 11 | +describe('General options propagation', () => { |
| 12 | + let component |
| 13 | + |
| 14 | + // sample origins |
| 15 | + const origins = ['https://exampleorigin.com'] |
| 16 | + |
| 17 | + beforeEach(async () => { |
| 18 | + mockCreateDistributionPromise.mockResolvedValueOnce({ |
| 19 | + Distribution: { |
| 20 | + Id: 'distribution123' |
| 21 | + } |
| 22 | + }) |
| 23 | + |
| 24 | + mockGetDistributionConfigPromise.mockResolvedValueOnce({ |
| 25 | + ETag: 'etag', |
| 26 | + DistributionConfig: { |
| 27 | + Origins: { |
| 28 | + Items: [] |
| 29 | + } |
| 30 | + } |
| 31 | + }) |
| 32 | + mockUpdateDistributionPromise.mockResolvedValueOnce({ |
| 33 | + Distribution: { |
| 34 | + Id: 'xyz' |
| 35 | + } |
| 36 | + }) |
| 37 | + |
| 38 | + component = await createComponent() |
| 39 | + }) |
| 40 | + |
| 41 | + it('create distribution with comment and update it', async () => { |
| 42 | + await component.default({ |
| 43 | + comment: 'test comment', |
| 44 | + origins |
| 45 | + }) |
| 46 | + |
| 47 | + expect(mockCreateDistribution).toBeCalledWith( |
| 48 | + expect.objectContaining({ |
| 49 | + DistributionConfig: expect.objectContaining({ |
| 50 | + Comment: 'test comment' |
| 51 | + }) |
| 52 | + }) |
| 53 | + ) |
| 54 | + |
| 55 | + await component.default({ |
| 56 | + comment: 'updated comment', |
| 57 | + origins |
| 58 | + }) |
| 59 | + |
| 60 | + expect(mockUpdateDistribution).toBeCalledWith( |
| 61 | + expect.objectContaining({ |
| 62 | + DistributionConfig: expect.objectContaining({ |
| 63 | + Comment: 'updated comment' |
| 64 | + }) |
| 65 | + }) |
| 66 | + ) |
| 67 | + }) |
| 68 | + |
| 69 | + it('create disabled distribution and update it', async () => { |
| 70 | + await component.default({ |
| 71 | + enabled: false, |
| 72 | + origins |
| 73 | + }) |
| 74 | + |
| 75 | + expect(mockCreateDistribution).toBeCalledWith( |
| 76 | + expect.objectContaining({ |
| 77 | + DistributionConfig: expect.objectContaining({ |
| 78 | + Enabled: false |
| 79 | + }) |
| 80 | + }) |
| 81 | + ) |
| 82 | + |
| 83 | + await component.default({ |
| 84 | + enabled: true, |
| 85 | + origins |
| 86 | + }) |
| 87 | + |
| 88 | + expect(mockUpdateDistribution).toBeCalledWith( |
| 89 | + expect.objectContaining({ |
| 90 | + DistributionConfig: expect.objectContaining({ |
| 91 | + Enabled: true |
| 92 | + }) |
| 93 | + }) |
| 94 | + ) |
| 95 | + }) |
| 96 | +}) |
0 commit comments