Skip to content

Commit 296bb3c

Browse files
committed
style: improve code formatting and consistency across multiple files
1 parent f5b9397 commit 296bb3c

11 files changed

Lines changed: 146 additions & 150 deletions

File tree

packages/backend/src/plugins/lambda/schemas.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ export const CreateFunctionBodySchema = Type.Object({
6666
}),
6767
description: Type.Optional(Type.String()),
6868
timeout: Type.Optional(Type.Integer({ minimum: 1, maximum: 900 })),
69-
memorySize: Type.Optional(
70-
Type.Integer({ minimum: 128, maximum: 10240 }),
71-
),
69+
memorySize: Type.Optional(Type.Integer({ minimum: 128, maximum: 10240 })),
7270
environment: Type.Optional(EnvironmentVariableSchema),
7371
architectures: Type.Optional(Type.Array(Type.String())),
7472
});
@@ -88,9 +86,7 @@ export const UpdateFunctionConfigBodySchema = Type.Object({
8886
runtime: Type.Optional(Type.String()),
8987
description: Type.Optional(Type.String()),
9088
timeout: Type.Optional(Type.Integer({ minimum: 1, maximum: 900 })),
91-
memorySize: Type.Optional(
92-
Type.Integer({ minimum: 128, maximum: 10240 }),
93-
),
89+
memorySize: Type.Optional(Type.Integer({ minimum: 128, maximum: 10240 })),
9490
environment: Type.Optional(EnvironmentVariableSchema),
9591
role: Type.Optional(Type.String()),
9692
});

packages/backend/src/plugins/lambda/service.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {
2+
type Architecture,
23
CreateEventSourceMappingCommand,
34
CreateFunctionCommand,
45
DeleteEventSourceMappingCommand,
56
DeleteFunctionCommand,
67
type EventSourcePosition,
78
GetFunctionCommand,
89
GetPolicyCommand,
9-
type Architecture,
1010
type InvocationType,
1111
InvokeCommand,
1212
type LambdaClient,
@@ -336,7 +336,7 @@ export class LambdaService {
336336
stmt.Principal?.Service,
337337
)
338338
.map((stmt) => {
339-
const service = stmt.Principal!.Service!;
339+
const service = stmt.Principal?.Service;
340340
const sourceArn =
341341
stmt.Condition?.ArnLike?.["AWS:SourceArn"] ??
342342
stmt.Condition?.ArnLike?.["aws:SourceArn"];
@@ -362,19 +362,19 @@ export class LambdaService {
362362
...(marker && { Marker: marker }),
363363
}),
364364
);
365-
const eventSourceMappings = (
366-
response.EventSourceMappings ?? []
367-
).map((m) => ({
368-
uuid: m.UUID ?? "",
369-
eventSourceArn: m.EventSourceArn,
370-
functionArn: m.FunctionArn,
371-
state: m.State,
372-
batchSize: m.BatchSize,
373-
lastModified: m.LastModified?.toISOString(),
374-
maximumBatchingWindowInSeconds: m.MaximumBatchingWindowInSeconds,
375-
startingPosition: m.StartingPosition,
376-
enabled: m.State === "Enabled" || m.State === "Creating",
377-
}));
365+
const eventSourceMappings = (response.EventSourceMappings ?? []).map(
366+
(m) => ({
367+
uuid: m.UUID ?? "",
368+
eventSourceArn: m.EventSourceArn,
369+
functionArn: m.FunctionArn,
370+
state: m.State,
371+
batchSize: m.BatchSize,
372+
lastModified: m.LastModified?.toISOString(),
373+
maximumBatchingWindowInSeconds: m.MaximumBatchingWindowInSeconds,
374+
startingPosition: m.StartingPosition,
375+
enabled: m.State === "Enabled" || m.State === "Creating",
376+
}),
377+
);
378378
return { eventSourceMappings, nextMarker: response.NextMarker };
379379
} catch (err) {
380380
mapLambdaError(err, functionName);

packages/backend/test/integration/lambda.integration.test.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { deflateRawSync } from "node:zlib";
2-
import type { FastifyInstance } from "fastify";
2+
import type { FastifyInstance, LightMyRequestResponse } from "fastify";
33
import { afterAll, beforeAll, describe, expect, it } from "vitest";
44
import { lambdaRoutes } from "../../src/plugins/lambda/routes.js";
55
import { buildApp, getLocalstackHeaders } from "./app-helper.js";
@@ -171,9 +171,11 @@ describe("Lambda Integration", () => {
171171
expect(body).toHaveProperty("functionArn");
172172
});
173173

174-
it("should update function configuration (change description)", { timeout: 60000 }, async () => {
174+
it("should update function configuration (change description)", {
175+
timeout: 60000,
176+
}, async () => {
175177
// Retry — LocalStack may need time after function creation
176-
let res;
178+
let res: LightMyRequestResponse | undefined;
177179
for (let i = 0; i < 15; i++) {
178180
res = await app.inject({
179181
method: "PUT",
@@ -185,9 +187,9 @@ describe("Lambda Integration", () => {
185187
await new Promise((r) => setTimeout(r, 2000));
186188
}
187189
// If still failing after retries, the route at least responded (not 404)
188-
expect(res!.statusCode).not.toBe(404);
189-
if (res!.statusCode === 200) {
190-
expect(res!.json().message).toContain("updated");
190+
expect(res?.statusCode).not.toBe(404);
191+
if (res?.statusCode === 200) {
192+
expect(res.json().message).toContain("updated");
191193
}
192194

193195
// Wait for function to settle after config update
@@ -206,7 +208,7 @@ describe("Lambda Integration", () => {
206208
});
207209

208210
it("should invoke function", { timeout: 60000 }, async () => {
209-
let res;
211+
let res: LightMyRequestResponse | undefined;
210212
for (let i = 0; i < 10; i++) {
211213
res = await app.inject({
212214
method: "POST",
@@ -217,9 +219,9 @@ describe("Lambda Integration", () => {
217219
if (res.statusCode === 200) break;
218220
await new Promise((r) => setTimeout(r, 2000));
219221
}
220-
expect(res!.statusCode).not.toBe(404);
221-
if (res!.statusCode === 200) {
222-
const body = res!.json();
222+
expect(res?.statusCode).not.toBe(404);
223+
if (res?.statusCode === 200) {
224+
const body = res.json();
223225
expect(body).toHaveProperty("statusCode");
224226
}
225227
});
@@ -271,8 +273,7 @@ describe("Lambda Integration", () => {
271273
url: `/${functionName}/event-source-mappings`,
272274
headers,
273275
payload: {
274-
eventSourceArn:
275-
"arn:aws:sqs:us-east-1:000000000000:test-trigger-queue",
276+
eventSourceArn: "arn:aws:sqs:us-east-1:000000000000:test-trigger-queue",
276277
batchSize: 5,
277278
enabled: true,
278279
},
@@ -326,7 +327,7 @@ describe("Lambda Integration", () => {
326327
});
327328

328329
it("should delete the function", { timeout: 60000 }, async () => {
329-
let res;
330+
let res: LightMyRequestResponse | undefined;
330331
for (let i = 0; i < 10; i++) {
331332
res = await app.inject({
332333
method: "DELETE",
@@ -337,7 +338,7 @@ describe("Lambda Integration", () => {
337338
await new Promise((r) => setTimeout(r, 2000));
338339
}
339340
// Function should be deleted (200) or already gone (404)
340-
expect([200, 404]).toContain(res!.statusCode);
341+
expect([200, 404]).toContain(res?.statusCode);
341342
});
342343

343344
it("should return 404 after deletion", async () => {

packages/backend/test/plugins/lambda/index.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ describe("lambdaPlugin index", () => {
2121
await app.register(lambdaPlugin, { prefix: "/api/lambda" });
2222
await app.ready();
2323

24-
const routes = app
25-
.printRoutes({ includeHooks: false })
26-
.split("\n")
27-
.filter(Boolean);
28-
29-
// Routes string should contain the lambda prefix paths
3024
const routeTree = app.printRoutes({ includeHooks: false });
3125
expect(routeTree).toContain("api/lambda");
3226

packages/backend/test/plugins/lambda/routes.test.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ interface MockLambdaService {
2929

3030
function createMockLambdaService(): MockLambdaService {
3131
return {
32-
listFunctions: vi.fn().mockResolvedValue({ functions: [], nextMarker: undefined }),
32+
listFunctions: vi
33+
.fn()
34+
.mockResolvedValue({ functions: [], nextMarker: undefined }),
3335
createFunction: vi.fn().mockResolvedValue({
3436
message: "Function 'my-function' created successfully",
3537
}),
@@ -66,10 +68,21 @@ function createMockLambdaService(): MockLambdaService {
6668
functionError: undefined,
6769
logResult: undefined,
6870
}),
69-
listVersions: vi.fn().mockResolvedValue({ versions: [], nextMarker: undefined }),
70-
listAliases: vi.fn().mockResolvedValue({ aliases: [], nextMarker: undefined }),
71-
getFunctionTriggers: vi.fn().mockResolvedValue({ eventSourceMappings: [], policyTriggers: [], nextMarker: undefined }),
72-
createEventSourceMapping: vi.fn().mockResolvedValue({ message: "Event source mapping created successfully", uuid: "new-uuid" }),
71+
listVersions: vi
72+
.fn()
73+
.mockResolvedValue({ versions: [], nextMarker: undefined }),
74+
listAliases: vi
75+
.fn()
76+
.mockResolvedValue({ aliases: [], nextMarker: undefined }),
77+
getFunctionTriggers: vi.fn().mockResolvedValue({
78+
eventSourceMappings: [],
79+
policyTriggers: [],
80+
nextMarker: undefined,
81+
}),
82+
createEventSourceMapping: vi.fn().mockResolvedValue({
83+
message: "Event source mapping created successfully",
84+
uuid: "new-uuid",
85+
}),
7386
deleteEventSourceMapping: vi.fn().mockResolvedValue({ success: true }),
7487
};
7588
}
@@ -97,7 +110,9 @@ describe("Lambda Routes", () => {
97110

98111
mockService = createMockLambdaService();
99112

100-
(LambdaServiceClass as unknown as Mock).mockImplementation(() => mockService);
113+
(LambdaServiceClass as unknown as Mock).mockImplementation(
114+
() => mockService,
115+
);
101116

102117
const mockClientCache = {
103118
getClients: vi.fn().mockReturnValue({ lambda: {} }),
@@ -234,7 +249,11 @@ describe("Lambda Routes", () => {
234249
it("should return 404 when function does not exist", async () => {
235250
const { AppError } = await import("../../../src/shared/errors.js");
236251
mockService.getFunction.mockRejectedValueOnce(
237-
new AppError("Function 'missing-fn' not found", 404, "FUNCTION_NOT_FOUND"),
252+
new AppError(
253+
"Function 'missing-fn' not found",
254+
404,
255+
"FUNCTION_NOT_FOUND",
256+
),
238257
);
239258
const response = await app.inject({
240259
method: "GET",

0 commit comments

Comments
 (0)