|
| 1 | +import { describe, test } from "@jest/globals"; |
| 2 | +import { expect } from "expect"; |
| 3 | + |
| 4 | +import { ExceptionlessClient } from "../../../src/ExceptionlessClient.js"; |
| 5 | +import { Event } from "../../../src/models/Event.js"; |
| 6 | +import { ConfigurationDefaultsPlugin } from "../../../src/plugins/default/ConfigurationDefaultsPlugin.js"; |
| 7 | +import { EventPluginContext } from "../../../src/plugins/EventPluginContext.js"; |
| 8 | +import { EventContext } from "../../../src/models/EventContext.js"; |
| 9 | + |
| 10 | +describe("ConfigurationDefaultsPlugin", () => { |
| 11 | + describe("should add default", () => { |
| 12 | + const userDataKey: string = "user"; |
| 13 | + const user = { |
| 14 | + id: 1, |
| 15 | + name: "Blake", |
| 16 | + password: "123456", |
| 17 | + passwordResetToken: "a reset token", |
| 18 | + myPassword: "123456", |
| 19 | + myPasswordValue: "123456", |
| 20 | + customValue: "Password", |
| 21 | + value: { |
| 22 | + Password: "123456" |
| 23 | + } |
| 24 | + }; |
| 25 | + |
| 26 | + const defaultTags: string[] = ["tag1", "tag2"]; |
| 27 | + |
| 28 | + const run = async (dataExclusions?: string[] | undefined): Promise<Event> => { |
| 29 | + const client = new ExceptionlessClient(); |
| 30 | + client.config.defaultTags.push(...defaultTags); |
| 31 | + client.config.defaultData[userDataKey] = user; |
| 32 | + |
| 33 | + if (dataExclusions) { |
| 34 | + client.config.addDataExclusions(...dataExclusions); |
| 35 | + } |
| 36 | + |
| 37 | + const ev: Event = <Event>{ type: "log", source: "test", data: {} }; |
| 38 | + |
| 39 | + const context = new EventPluginContext(client, ev, new EventContext()); |
| 40 | + const plugin = new ConfigurationDefaultsPlugin(); |
| 41 | + await plugin.run(context); |
| 42 | + |
| 43 | + return context.event; |
| 44 | + } |
| 45 | + |
| 46 | + test("tags", async () => { |
| 47 | + const ev = await run(); |
| 48 | + expect(ev.tags).toStrictEqual(defaultTags) |
| 49 | + }); |
| 50 | + |
| 51 | + test("user", async () => { |
| 52 | + const ev = await run(); |
| 53 | + expect(ev.data).toBeDefined(); |
| 54 | + expect(ev.data && ev.data[userDataKey]).toStrictEqual(user); |
| 55 | + }); |
| 56 | + |
| 57 | + test("pruned user", async () => { |
| 58 | + const ev = await run(["*password*"]); |
| 59 | + expect(ev.data).toBeDefined(); |
| 60 | + |
| 61 | + const expected = { "id": 1, "name": "Blake", "customValue": "Password", "value": {} }; |
| 62 | + expect(ev.data && ev.data[userDataKey]).toStrictEqual(expected); |
| 63 | + }); |
| 64 | + }); |
| 65 | +}); |
0 commit comments