Skip to content

Commit 9b1ef33

Browse files
committed
Fix send objects in to service
1 parent 059b940 commit 9b1ef33

File tree

6 files changed

+42
-37
lines changed

6 files changed

+42
-37
lines changed

src/DuckBug/DuckBugProvider.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class DuckBugProvider implements Provider {
1414
time: this.getTimeStamp(),
1515
level: logLevel.WARN,
1616
message: this.convertArgsToString(args[0]),
17-
context: this.convertArgsToString(args.slice(1)),
17+
context: args.slice(1),
1818
});
1919
}
2020

@@ -23,7 +23,7 @@ export class DuckBugProvider implements Provider {
2323
time: this.getTimeStamp(),
2424
level: logLevel.ERROR,
2525
message: this.convertArgsToString(args[0]),
26-
context: this.convertArgsToString(args.slice(1)),
26+
context: args.slice(1),
2727
});
2828
}
2929

@@ -32,7 +32,7 @@ export class DuckBugProvider implements Provider {
3232
time: this.getTimeStamp(),
3333
level: logLevel.INFO,
3434
message: this.convertArgsToString(args[0]),
35-
context: this.convertArgsToString(args.slice(1)),
35+
context: args.slice(1),
3636
});
3737
}
3838

@@ -41,7 +41,7 @@ export class DuckBugProvider implements Provider {
4141
time: this.getTimeStamp(),
4242
level,
4343
message: tag,
44-
context: JSON.stringify(payload),
44+
context: payload,
4545
});
4646
}
4747

src/DuckBug/Log.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ export type Log = {
44
message: string;
55
level: LogLevel;
66
time: number;
7-
context: string | undefined;
7+
context: object | undefined;
88
};

src/SDK/DuckSDK.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export class DuckSDK {
3232
this.sendReportToPlugins(tag, logLevel.FATAL, payload);
3333
}
3434

35-
quack() {}
35+
quack(tag: string, error: Error) {
36+
this.providers.forEach((plugin) => plugin.quack(tag, error));
37+
}
3638

3739
private sendReportToPlugins(tag: string, level: LogLevel, payload?: object) {
3840
this.providers.forEach((plugin) => plugin.report(tag, level, payload));

tests/DuckBug/DuckBugProvider.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe("DuckBugProvider", () => {
5353
time: 12345,
5454
level: logLevel.WARN,
5555
message: "Warning message",
56-
context: JSON.stringify([context1, context2]),
56+
context: [context1, context2],
5757
});
5858
});
5959

@@ -66,7 +66,7 @@ describe("DuckBugProvider", () => {
6666
time: 12345,
6767
level: logLevel.WARN,
6868
message: "Single warning",
69-
context: "[]",
69+
context: [],
7070
});
7171
});
7272

@@ -79,7 +79,7 @@ describe("DuckBugProvider", () => {
7979
time: 12345,
8080
level: logLevel.WARN,
8181
message: "undefined",
82-
context: "[]",
82+
context: [],
8383
});
8484
});
8585
});
@@ -99,7 +99,7 @@ describe("DuckBugProvider", () => {
9999
time: 54321,
100100
level: logLevel.ERROR,
101101
message: "Error message",
102-
context: JSON.stringify([context1, context2]),
102+
context: [context1, context2],
103103
});
104104
});
105105

@@ -114,7 +114,7 @@ describe("DuckBugProvider", () => {
114114
time: 54321,
115115
level: logLevel.ERROR,
116116
message: '{"type":"TypeError","message":"Cannot read property"}',
117-
context: "[]",
117+
context: [],
118118
});
119119
});
120120
});
@@ -134,7 +134,7 @@ describe("DuckBugProvider", () => {
134134
time: 67890,
135135
level: logLevel.INFO,
136136
message: "Info message",
137-
context: JSON.stringify([context1, context2]),
137+
context: [context1, context2],
138138
});
139139
});
140140

@@ -147,7 +147,7 @@ describe("DuckBugProvider", () => {
147147
time: 67890,
148148
level: logLevel.INFO,
149149
message: "Message",
150-
context: JSON.stringify(["arg1", "arg2", "arg3"]),
150+
context: ["arg1", "arg2", "arg3"],
151151
});
152152
});
153153
});
@@ -166,7 +166,7 @@ describe("DuckBugProvider", () => {
166166
time: 11111,
167167
level: logLevel.DEBUG,
168168
message: tag,
169-
context: '{"userId":123,"action":"click"}',
169+
context: payload,
170170
});
171171
});
172172

@@ -206,7 +206,7 @@ describe("DuckBugProvider", () => {
206206
time: 33333,
207207
level,
208208
message: `TAG_${index}`,
209-
context: `{"index":${index}}`,
209+
context: { index },
210210
});
211211
});
212212
});
@@ -269,14 +269,14 @@ describe("DuckBugProvider", () => {
269269
time: 99999,
270270
level: logLevel.INFO,
271271
message: "String",
272-
context: JSON.stringify([
272+
context: [
273273
123,
274274
true,
275275
null,
276276
undefined,
277277
{ obj: "value" },
278278
["array", "item"],
279-
]),
279+
],
280280
});
281281
});
282282
});

tests/SDK/DuckSDK.test.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -288,24 +288,26 @@ describe("DuckSDK", () => {
288288
sdk = new DuckSDK(providers);
289289
});
290290

291-
it("should be a no-op method", () => {
292-
expect(() => sdk.quack()).not.toThrow();
291+
it("should call quack on all providers with tag and error", () => {
292+
const tag = "QUACK_TAG";
293+
const error = new Error("Test error");
294+
295+
sdk.quack(tag, error);
296+
297+
expect(mockProvider1.quack).toHaveBeenCalledTimes(1);
298+
expect(mockProvider1.quack).toHaveBeenCalledWith(tag, error);
299+
expect(mockProvider2.quack).toHaveBeenCalledTimes(1);
300+
expect(mockProvider2.quack).toHaveBeenCalledWith(tag, error);
293301
});
294302

295-
it("should not call any provider methods", () => {
296-
sdk.quack();
303+
it("should work with different error types", () => {
304+
const tag = "ERROR_TAG";
305+
const error = new TypeError("Type error test");
297306

298-
expect(mockProvider1.log).not.toHaveBeenCalled();
299-
expect(mockProvider1.warn).not.toHaveBeenCalled();
300-
expect(mockProvider1.error).not.toHaveBeenCalled();
301-
expect(mockProvider1.report).not.toHaveBeenCalled();
302-
expect(mockProvider1.quack).not.toHaveBeenCalled();
307+
sdk.quack(tag, error);
303308

304-
expect(mockProvider2.log).not.toHaveBeenCalled();
305-
expect(mockProvider2.warn).not.toHaveBeenCalled();
306-
expect(mockProvider2.error).not.toHaveBeenCalled();
307-
expect(mockProvider2.report).not.toHaveBeenCalled();
308-
expect(mockProvider2.quack).not.toHaveBeenCalled();
309+
expect(mockProvider1.quack).toHaveBeenCalledWith(tag, error);
310+
expect(mockProvider2.quack).toHaveBeenCalledWith(tag, error);
309311
});
310312
});
311313

tests/integration.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ describe("DuckBug Integration Tests", () => {
296296
time: 1640995200000,
297297
level: logLevel.WARN,
298298
message: "DATA_INTEGRITY_TEST",
299-
context: JSON.stringify(testData),
299+
context: testData,
300300
}),
301301
});
302302
});
@@ -328,46 +328,47 @@ describe("DuckBug Integration Tests", () => {
328328
time: 1640995200000,
329329
level: "DEBUG",
330330
message: "STRING_TEST",
331-
context: '"simple string"',
331+
context: "simple string",
332332
}),
333333
);
334334
expect(calls[1][1]?.body).toContain(
335335
JSON.stringify({
336336
time: 1640995200000,
337337
level: "DEBUG",
338338
message: "NUMBER_TEST",
339-
context: "42",
339+
context: 42,
340340
}),
341341
);
342342
expect(calls[2][1]?.body).toContain(
343343
JSON.stringify({
344344
time: 1640995200000,
345345
level: "DEBUG",
346346
message: "BOOLEAN_TEST",
347-
context: "true",
347+
context: true,
348348
}),
349349
);
350350
expect(calls[3][1]?.body).toContain(
351351
JSON.stringify({
352352
time: 1640995200000,
353353
level: "DEBUG",
354354
message: "NULL_TEST",
355-
context: "null",
355+
context: null,
356356
}),
357357
);
358358
expect(calls[4][1]?.body).toContain(
359359
JSON.stringify({
360360
time: 1640995200000,
361361
level: "DEBUG",
362362
message: "UNDEFINED_TEST",
363+
context: undefined,
363364
}),
364365
);
365366
expect(calls[5][1]?.body).toContain(
366367
JSON.stringify({
367368
time: 1640995200000,
368369
level: "DEBUG",
369370
message: "ARRAY_TEST",
370-
context: "[1,2,3]",
371+
context: [1, 2, 3],
371372
}),
372373
);
373374
});

0 commit comments

Comments
 (0)