Skip to content

Commit

Permalink
fix: cleanup tracking interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathannorris committed Nov 18, 2024
1 parent 8fb3ca8 commit 7eb13be
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 5 deletions.
3 changes: 1 addition & 2 deletions sdk/nodejs/src/open-feature/DevCycleProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
TargetingKeyMissingError,
InvalidContextError,
ProviderStatus,
Tracking,
TrackingEventDetails,
} from '@openfeature/server-sdk'
import {
Expand Down Expand Up @@ -40,7 +39,7 @@ type EvaluationContextObject = {
[key: string]: EvaluationContextValue
}

export class DevCycleProvider implements Provider, Tracking {
export class DevCycleProvider implements Provider {
readonly metadata: ProviderMetadata = {
name: 'devcycle-nodejs-provider',
} as const
Expand Down
65 changes: 65 additions & 0 deletions sdk/openfeature-web-provider/__tests__/DevCycleProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,69 @@ describe('DevCycleProvider Unit Tests', () => {
})
})
})

describe('Tracking Events', () => {
let trackMock: any
let openFeatureClient: Client
let provider: DevCycleProvider

beforeEach(async () => {
const init = await initOFClient()
openFeatureClient = init.ofClient
provider = init.provider

if (provider.devcycleClient) {
trackMock = jest
.spyOn(provider.devcycleClient, 'track')
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
.mockResolvedValue()
}
})

afterEach(() => {
trackMock?.mockClear()
})

it('should track an event with just a name', () => {
openFeatureClient.track('event-name')

expect(trackMock).toHaveBeenCalledWith({
type: 'event-name',
value: undefined,
metaData: undefined,
})
})

it('should track an event with value and metadata', () => {
openFeatureClient.track('event-name', {
value: 123,
someKey: 'someValue',
otherKey: true,
})

expect(trackMock).toHaveBeenCalledWith({
type: 'event-name',
value: 123,
metaData: {
someKey: 'someValue',
otherKey: true,
},
})
})

it('should track an event with just metadata', () => {
openFeatureClient.track('event-name', {
someKey: 'someValue',
})

expect(trackMock).toHaveBeenCalledWith({
type: 'event-name',
value: undefined,
metaData: {
someKey: 'someValue',
},
})
})
})
})
6 changes: 3 additions & 3 deletions sdk/openfeature-web-provider/src/DevCycleProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
ResolutionDetails,
StandardResolutionReasons,
TargetingKeyMissingError,
Tracking,
TrackingEventDetails,
} from '@openfeature/web-sdk'
// Need to disable this to keep the working jest mock
Expand Down Expand Up @@ -43,7 +42,7 @@ type EvaluationContextObject = {
[key: string]: EvaluationContextValue
}

export default class DevCycleProvider implements Provider, Tracking {
export default class DevCycleProvider implements Provider {
readonly metadata: ProviderMetadata = {
name: 'devcycle-web-provider',
} as const
Expand Down Expand Up @@ -118,8 +117,9 @@ export default class DevCycleProvider implements Provider, Tracking {
)
}

track(
track?(
trackingEventName: string,
context?: EvaluationContext,
trackingEventDetails?: TrackingEventDetails,
): void {
this._devcycleClient?.track({
Expand Down

0 comments on commit 7eb13be

Please sign in to comment.