Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(plugin-client-ip): convert tests #1017

Merged
merged 2 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = {
testsForPackage('plugin-browser-context'),
testsForPackage('plugin-browser-device'),
testsForPackage('plugin-browser-request'),
testsForPackage('plugin-client-ip'),
testsForPackage('plugin-window-unhandled-rejection'),
testsForPackage('plugin-window-onerror'),
testsForPackage('plugin-strip-query-string'),
Expand Down
4 changes: 3 additions & 1 deletion packages/core/client.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client, OnErrorCallback, Config, Breadcrumb, Session, OnSessionCallback, OnBreadcrumbCallback, Plugin, Device, App } from './types'
import { Client, OnErrorCallback, Config, Breadcrumb, Session, OnSessionCallback, OnBreadcrumbCallback, Plugin, Device, App, User } from './types'
import EventWithInternals from './event'

interface LoggerConfig {
Expand Down Expand Up @@ -46,6 +46,8 @@ export default class ClientWithInternals<T extends Config = Config> extends Clie
_delivery: Delivery
_setDelivery: (handler: (client: Client) => Delivery) => void

_user: User

_metadata: { [key: string]: any }

startSession(): ClientWithInternals
Expand Down
1 change: 1 addition & 0 deletions packages/core/event.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface HandledState {
export default class EventWithInternals extends Event {
constructor (errorClass: string, errorMessage: string, stacktrace: any[], handledState?: HandledState, originalError?: Error)
_metadata: { [key: string]: any }
_user: User
_handledState: HandledState
_session?: Session
toJSON(): {
Expand Down
7 changes: 1 addition & 6 deletions packages/plugin-client-ip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@
"files": [
"*.js"
],
"scripts": {
"test": "nyc --reporter=lcov -- jasmine '!(node_modules)/**/*.test.js'"
},
"author": "Bugsnag",
"license": "MIT",
"devDependencies": {
"@bugsnag/core": "^7.3.3",
"jasmine": "^3.1.0",
"nyc": "^12.0.2"
"@bugsnag/core": "^7.3.3"
},
"peerDependencies": {
"@bugsnag/core": "^7.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
const { describe, it, expect } = global
import plugin from '../'

const plugin = require('../')

const Client = require('@bugsnag/core/client')
import Client, { EventDeliveryPayload } from '@bugsnag/core/client'

describe('plugin: ip', () => {
it('does nothing when collectUserIp=true', () => {
const client = new Client({ apiKey: 'API_KEY_YEAH' }, undefined, [plugin])
const payloads = []
const payloads: EventDeliveryPayload[] = []

client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload) }))
client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload), sendSession: () => {} }))
client.notify(new Error('noooo'), event => { event.request = { some: 'detail' } })

expect(payloads.length).toEqual(1)
Expand All @@ -18,11 +16,11 @@ describe('plugin: ip', () => {

it('doesn’t overwrite an existing user id', () => {
const client = new Client({ apiKey: 'API_KEY_YEAH', collectUserIp: false }, undefined, [plugin])
const payloads = []
const payloads: EventDeliveryPayload[] = []

client._user = { id: 'foobar' }

client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload) }))
client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload), sendSession: () => {} }))
client.notify(new Error('noooo'))

expect(payloads.length).toEqual(1)
Expand All @@ -32,11 +30,11 @@ describe('plugin: ip', () => {

it('overwrites a user id if it is explicitly `undefined`', () => {
const client = new Client({ apiKey: 'API_KEY_YEAH', collectUserIp: false }, undefined, [plugin])
const payloads = []
const payloads: EventDeliveryPayload[] = []

client._user = { id: undefined }

client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload) }))
client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload), sendSession: () => {} }))
client.notify(new Error('noooo'))

expect(payloads.length).toEqual(1)
Expand All @@ -46,9 +44,9 @@ describe('plugin: ip', () => {

it('redacts user IP if none is provided', () => {
const client = new Client({ apiKey: 'API_KEY_YEAH', collectUserIp: false }, undefined, [plugin])
const payloads = []
const payloads: EventDeliveryPayload[] = []

client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload) }))
client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload), sendSession: () => {} }))
client.notify(new Error('noooo'))

expect(payloads.length).toEqual(1)
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@
"packages/plugin-react-native-client-sync",
"packages/plugin-react-native-event-sync",
"packages/plugin-server-session",

"packages/plugin-react",
"packages/plugin-vue",
"packages/plugin-express",
"packages/plugin-koa",
"packages/plugin-restify",
"packages/node",
"packages/react-native",
"packages/plugin-client-ip",
"packages/plugin-window-unhandled-rejection",
"packages/plugin-window-onerror",
"packages/plugin-strip-query-string",
Expand Down