🎥 Make videos programmatically with React
delete fn
Jonny Burgere78e5195eedf
diff --git a/packages/lambda/src/api/__mocks__/create-function.ts b/packages/lambda/src/api/__mocks__/create-function.tsindex 34705c6562..d8a14b667d 100644--- a/packages/lambda/src/api/__mocks__/create-function.ts+++ b/packages/lambda/src/api/__mocks__/create-function.ts@@ -8,12 +8,15 @@ export const createFunction: typeof original = async (input) => {throw new TypeError('did not ensure layer for ' + input.region);}- addFunction({- functionName: input.functionName,- memorySizeInMb: 1024,- timeoutInSeconds: input.timeoutInSeconds,- version: CURRENT_VERSION,- });+ addFunction(+ {+ functionName: input.functionName,+ memorySizeInMb: 1024,+ timeoutInSeconds: input.timeoutInSeconds,+ version: CURRENT_VERSION,+ },+ input.region+ );return Promise.resolve({FunctionName: input.functionName,});diff --git a/packages/lambda/src/api/__mocks__/delete-function.ts b/packages/lambda/src/api/__mocks__/delete-function.tsnew file mode 100644index 0000000000..75adb9bd2f--- /dev/null+++ b/packages/lambda/src/api/__mocks__/delete-function.ts@@ -0,0 +1,8 @@+import {deleteFunction as original} from '../delete-function';+import {deleteMockFunction} from '../mock-functions';++export const deleteFunction: typeof original = ({region, functionName}) => {+ deleteMockFunction(functionName, region);++ return Promise.resolve();+};diff --git a/packages/lambda/src/api/__mocks__/get-functions.ts b/packages/lambda/src/api/__mocks__/get-functions.tsindex e996f40243..4266c03a6b 100644--- a/packages/lambda/src/api/__mocks__/get-functions.ts+++ b/packages/lambda/src/api/__mocks__/get-functions.ts@@ -1,6 +1,6 @@import {getFunctions as original} from '../get-functions';import {getAllMockFunctions} from '../mock-functions';-export const getFunctions: typeof original = async () => {- return getAllMockFunctions();+export const getFunctions: typeof original = async ({region}) => {+ return getAllMockFunctions(region);};diff --git a/packages/lambda/src/api/mock-functions.ts b/packages/lambda/src/api/mock-functions.tsindex 1541315992..b111fc5bee 100644--- a/packages/lambda/src/api/mock-functions.ts+++ b/packages/lambda/src/api/mock-functions.ts@@ -1,23 +1,26 @@+import {AwsRegion} from '..';import {FunctionInfo} from './get-function-info';-export let mockFunctionsStore: FunctionInfo[] = [];+export let mockFunctionsStore: (FunctionInfo & {region: AwsRegion})[] = [];-export const addFunction = (fn: FunctionInfo) => {- mockFunctionsStore.push(fn);+export const addFunction = (fn: FunctionInfo, region: AwsRegion) => {+ mockFunctionsStore.push({...fn, region});};-export const deleteFunction = (name: string) => {+export const deleteMockFunction = (name: string, region: string) => {mockFunctionsStore = mockFunctionsStore.filter(- (fn) => fn.functionName !== name+ (fn) => fn.functionName !== name && fn.region !== region);};-export const findFunction = (name: string) => {- return mockFunctionsStore.find((n) => n.functionName === name);+export const findFunction = (name: string, region: string) => {+ return mockFunctionsStore.find(+ (n) => n.functionName === name && region === n.region+ );};-export const getAllMockFunctions = () => {- return mockFunctionsStore;+export const getAllMockFunctions = (region: string) => {+ return mockFunctionsStore.filter((f) => f.region === region);};export const cleanFnStore = () => {diff --git a/packages/lambda/src/test/integration/deploy-function.test.ts b/packages/lambda/src/test/integration/deploy-function.test.tsindex c303b66695..a8b84f5b9c 100644--- a/packages/lambda/src/test/integration/deploy-function.test.ts+++ b/packages/lambda/src/test/integration/deploy-function.test.ts@@ -1,3 +1,4 @@+import {deleteFunction} from '../../api/delete-function';import {deployFunction} from '../../api/deploy-function';import {ensureLambdaBinaries} from '../../api/ensure-lambda-binaries';import {getFunctions} from '../../api/get-functions';@@ -14,6 +15,7 @@ jest.mock('../../api/bucket-exists');jest.mock('../../api/clean-items');jest.mock('../../api/ensure-lambda-binaries');jest.mock('../../api/create-function');+jest.mock('../../api/delete-function');jest.mock('../../api/bundle-lambda');jest.mock('../../api/get-functions');jest.mock('../../shared/get-account-id');@@ -62,6 +64,29 @@ test('Should be able to get the function afterwards', async () => {memorySizeInMb: 1024,timeoutInSeconds: 120,version: '2021-09-15',+ region: 'us-east-1',},]);});++test('Should be able to delete the function', async () => {+ cleanFnStore();+ const {layerArn} = await ensureLambdaBinaries('us-east-1');++ const {functionName} = await deployFunction({+ layerArn,+ memorySizeInMb: 2048,+ region: 'us-east-1',+ timeoutInSeconds: 120,+ });+ expect(functionName).toBe('remotion-render-abcdef');+ await deleteFunction({+ region: 'us-east-1',+ functionName: 'remotion-render-abcdef',+ });+ const fns = await getFunctions({+ region: 'us-east-1',+ compatibleOnly: true,+ });+ expect(fns).toEqual([]);+});