Skip to content

🎥 Make videos programmatically with React

test deployfunction

Jonny Burgerf19973ea569e
diff --git a/packages/lambda/src/api/__mocks__/deploy-function.ts b/packages/lambda/src/api/__mocks__/deploy-function.ts
new file mode 100644
index 0000000000..ea1ad700f2
--- /dev/null
+++ b/packages/lambda/src/api/__mocks__/deploy-function.ts
@@ -0,0 +1,12 @@
+import {deployFunction as original} from '../deploy-function';
+import {isLayerEnsured} from './mock-layers';
+
+export const deployFunction: typeof original = async (input) => {
+ if (!isLayerEnsured(input.region)) {
+ throw new TypeError('did not ensure layer for ' + input.region);
+ }
+
+ return Promise.resolve({
+ functionName: 'hithere',
+ });
+};
diff --git a/packages/lambda/src/api/__mocks__/ensure-lambda-binaries.ts b/packages/lambda/src/api/__mocks__/ensure-lambda-binaries.ts
new file mode 100644
index 0000000000..bc752e5dad
--- /dev/null
+++ b/packages/lambda/src/api/__mocks__/ensure-lambda-binaries.ts
@@ -0,0 +1,9 @@
+import {ensureLambdaBinaries as original} from '../ensure-lambda-binaries';
+import {ensureLayer} from './mock-layers';
+
+export const ensureLambdaBinaries: typeof original = (region) => {
+ ensureLayer(region);
+ return Promise.resolve({
+ layerArn: region,
+ });
+};
diff --git a/packages/lambda/src/api/__mocks__/mock-layers.ts b/packages/lambda/src/api/__mocks__/mock-layers.ts
new file mode 100644
index 0000000000..233f0f8e44
--- /dev/null
+++ b/packages/lambda/src/api/__mocks__/mock-layers.ts
@@ -0,0 +1,9 @@
+export const layersEnsured: {[key: string]: boolean} = {};
+
+export const ensureLayer = (layer: string) => {
+ layersEnsured[layer] = true;
+};
+
+export const isLayerEnsured = (layer: string): boolean => {
+ return Boolean(layersEnsured[layer]);
+};
diff --git a/packages/lambda/src/test/integration/deploy-function.test.ts b/packages/lambda/src/test/integration/deploy-function.test.ts
new file mode 100644
index 0000000000..50aba95c40
--- /dev/null
+++ b/packages/lambda/src/test/integration/deploy-function.test.ts
@@ -0,0 +1,37 @@
+import {deployFunction} from '../../api/deploy-function';
+import {ensureLambdaBinaries} from '../../api/ensure-lambda-binaries';
+
+jest.mock('../../api/get-buckets');
+jest.mock('../../functions/helpers/io');
+jest.mock('../../shared/bundle-site');
+jest.mock('../../shared/random-hash');
+jest.mock('../../api/enable-s3-website');
+jest.mock('../../api/create-bucket');
+jest.mock('../../api/upload-dir');
+jest.mock('../../api/bucket-exists');
+jest.mock('../../api/clean-items');
+jest.mock('../../api/deploy-function');
+jest.mock('../../api/ensure-lambda-binaries');
+
+test('Should be able to deploy function', async () => {
+ const {layerArn} = await ensureLambdaBinaries('us-east-1');
+
+ const {functionName} = await deployFunction({
+ layerArn,
+ memorySizeInMb: 2048,
+ region: 'us-east-1',
+ timeoutInSeconds: 120,
+ });
+ expect(functionName).toBe('hithere');
+});
+
+test('Should not be able to deploy function if binaries were not ensured', async () => {
+ await expect(() =>
+ deployFunction({
+ layerArn: 'us-east-2',
+ memorySizeInMb: 2048,
+ region: 'us-east-2',
+ timeoutInSeconds: 120,
+ })
+ ).rejects.toThrow(/did not ensure layer for/);
+});