-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathevent.test.ts
More file actions
71 lines (61 loc) · 1.82 KB
/
Copy pathevent.test.ts
File metadata and controls
71 lines (61 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import { sync as rimrafSync } from 'rimraf';
import { LocalSAMGenerator } from '../lib/index';
import { generateLocalSAM } from '../lib/index';
import { zipFolder } from './utils';
jest.setTimeout(120_000);
describe('integration:Event', () => {
describe('single lambda', () => {
const functionName = 'first';
let lambdaSAM: LocalSAMGenerator;
let tmpdir: string;
beforeAll(async () => {
// Generate zip from the fixture
const randomTmpId = Math.random().toString().slice(2);
tmpdir = path.resolve(os.tmpdir(), `sammy-${randomTmpId}`);
fs.mkdirSync(tmpdir, { recursive: true });
const lambdaZip = path.join(tmpdir, 'first.zip');
await zipFolder(path.resolve(__dirname, 'fixture/'), lambdaZip);
lambdaSAM = await generateLocalSAM({
lambdas: {
[functionName]: {
filename: 'first.zip',
handler: 'handler.handler',
runtime: 'nodejs22.x',
},
},
cwd: tmpdir,
onData(data) {
console.log(data.toString());
},
onError(data) {
console.log(data.toString());
},
});
generateLocalSAM;
await lambdaSAM.start();
});
afterAll(async () => {
await lambdaSAM.stop();
rimrafSync(tmpdir);
});
test('Invoke through AWS SDK', async () => {
const response = await lambdaSAM.sendEvent(
functionName,
'RequestResponse',
''
);
expect(response.StatusCode).toBe(200);
expect(JSON.parse(response.Payload!.toString())).toEqual({
isBase64Encoded: false,
statusCode: 200,
body: 'Hello World!',
headers: {
'content-type': 'application/json',
},
});
});
});
});