Skip to content

Commit

Permalink
feat: update config url to support v2 configs test
Browse files Browse the repository at this point in the history
  • Loading branch information
suthar26 committed Aug 20, 2024
1 parent 6c46d78 commit a8843b6
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 23 deletions.
2 changes: 1 addition & 1 deletion harness/features/allFeatures.local.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('allFeatures Tests - Local', () => {

beforeEach(async () => {
testClient = new LocalTestClient(sdkName)
const configRequestUrl = testClient.getValidConfigPath()
const configRequestUrl = testClient.getValidConfigPath(hasCapability(sdkName, Capabilities.v2Config))
scope.get(configRequestUrl).times(2).reply(500)
await testClient.createClient(true, {
configPollingIntervalMS: 60000,
Expand Down
3 changes: 2 additions & 1 deletion harness/features/allVariables.local.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ describe('allVariables Tests - Local', () => {
it('should return an empty object if client is not initialized', async () => {
const delayClient = new LocalTestClient(sdkName)

const configRequestUrl = delayClient.getValidConfigPath(hasCapability(sdkName, Capabilities.v2Config))
let interceptor = scope
.get(delayClient.getValidConfigPath())
.get(configRequestUrl)
.delay(2000)
interceptor.reply(200, delayClient.getValidConfig())

Expand Down
3 changes: 2 additions & 1 deletion harness/features/clientCustomData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ describe('Client Custom Data Tests', () => {

it('should do nothing when client has not initialized', async () => {
const client = new LocalTestClient(sdkName)
const configCall = scope.get(client.getValidConfigPath())
const configRequestUrl = client.getValidConfigPath(hasCapability(sdkName, Capabilities.v2Config))
const configCall = scope.get(configRequestUrl)

configCall.delay(1000).reply(200, client.getValidConfig())

Expand Down
34 changes: 20 additions & 14 deletions harness/features/initialize.local.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('Initialize Tests - Local', () => {
it('calls initialize promise/callback when config fails to be retrieved', async () => {
const testClient = new LocalTestClient(sdkName)

scope.get(testClient.getValidConfigPath()).times(2).reply(500)
scope.get(testClient.getValidConfigPath(hasCapability(sdkName, Capabilities.v2Config))).times(2).reply(500)

await testClient.createClient(true, {
configPollingIntervalMS: 10000,
Expand All @@ -87,14 +87,14 @@ describe('Initialize Tests - Local', () => {
it('defaults variable when config fails to be retrieved, and then recovers', async () => {
const testClient = new LocalTestClient(sdkName)

scope.get(testClient.getValidConfigPath()).times(2).reply(500)
scope.get(testClient.getValidConfigPath(hasCapability(sdkName, Capabilities.v2Config))).times(2).reply(500)
scope.post(`/client/${testClient.clientId}/v1/events/batch`).reply(201)

await testClient.createClient(true, {
configPollingIntervalMS: 3000,
})
scope
.get(testClient.getValidConfigPath())
.get(testClient.getValidConfigPath(hasCapability(sdkName, Capabilities.v2Config)))
.reply(200, testClient.getValidConfig)
const variable = await testClient.callVariable(
shouldBucketUser,
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('Initialize Tests - Local', () => {
async () => {
const testClient = new LocalTestClient(sdkName)

scope.get(testClient.getValidConfigPath()).reply(403)
scope.get(testClient.getValidConfigPath(hasCapability(sdkName, Capabilities.v2Config))).reply(403)

const response = await testClient.createClient(
true,
Expand All @@ -141,8 +141,9 @@ describe('Initialize Tests - Local', () => {

it('fetches config again after 3 seconds when config polling interval is overriden', async () => {
const testClient = new LocalTestClient(sdkName)
const configRequestUrl = testClient.getValidConfigPath(hasCapability(sdkName, Capabilities.v2Config))
scope
.get(testClient.getValidConfigPath())
.get(configRequestUrl)
.times(2)
.reply(200, testClient.getValidConfig)
addEventsBatchMock(testClient)
Expand All @@ -160,8 +161,9 @@ describe('Initialize Tests - Local', () => {

it('uses the same config if the etag matches', async () => {
const testClient = new LocalTestClient(sdkName)
const configRequestUrl = testClient.getValidConfigPath(hasCapability(sdkName, Capabilities.v2Config))
scope
.get(testClient.getValidConfigPath())
.get(configRequestUrl)
.reply(200, testClient.getValidConfig(), {
ETag: 'test-etag',
'Last-Modified': lastModifiedDate.toUTCString(),
Expand All @@ -170,7 +172,7 @@ describe('Initialize Tests - Local', () => {

if (hasCapability(sdkName, Capabilities.lastModifiedHeader)) {
scope
.get(testClient.getValidConfigPath())
.get(configRequestUrl)
.matchHeader('If-None-Match', 'test-etag')
.matchHeader(
'If-Modified-Since',
Expand All @@ -179,7 +181,7 @@ describe('Initialize Tests - Local', () => {
.reply(304, {})
} else {
scope
.get(testClient.getValidConfigPath())
.get(configRequestUrl)
.matchHeader('If-None-Match', 'test-etag')
.reply(304, {})
}
Expand Down Expand Up @@ -211,8 +213,9 @@ describe('Initialize Tests - Local', () => {

it('uses the same config if the refetch fails, after retrying once', async () => {
const testClient = new LocalTestClient(sdkName, scope)
const configRequestUrl = testClient.getValidConfigPath(hasCapability(sdkName, Capabilities.v2Config))

scope.get(testClient.getValidConfigPath()).times(2).reply(503, {})
scope.get(configRequestUrl).times(2).reply(503, {})

await testClient.createClient(true, {
configPollingIntervalMS: 1000,
Expand All @@ -237,8 +240,9 @@ describe('Initialize Tests - Local', () => {

it('uses the same config if the response is invalid JSON', async () => {
const testClient = new LocalTestClient(sdkName, scope)
const configRequestUrl = testClient.getValidConfigPath(hasCapability(sdkName, Capabilities.v2Config))

scope.get(testClient.getValidConfigPath()).reply(200, "I'm not JSON!")
scope.get(configRequestUrl).reply(200, "I'm not JSON!")

await testClient.createClient(true, {
configPollingIntervalMS: 1000,
Expand All @@ -263,10 +267,11 @@ describe('Initialize Tests - Local', () => {

it('uses the same config if the response is valid JSON but invalid data', async () => {
const testClient = new LocalTestClient(sdkName, scope)
const configRequestUrl = testClient.getValidConfigPath(hasCapability(sdkName, Capabilities.v2Config))
addEventsBatchMock(testClient)

scope
.get(testClient.getValidConfigPath())
.get(configRequestUrl)
.reply(200, '{"snatch_movie_quote": "d\'ya like dags?"}')

await testClient.createClient(true, {
Expand Down Expand Up @@ -295,7 +300,8 @@ describe('Initialize Tests - Local', () => {

it('uses the new config when etag changes, and flushes existing events', async () => {
const testClient = new LocalTestClient(sdkName)
const firstConfig = scope.get(testClient.getValidConfigPath()).times(1)
const configRequestUrl = testClient.getValidConfigPath(hasCapability(sdkName, Capabilities.v2Config))
const firstConfig = scope.get(configRequestUrl).times(1)

firstConfig.reply(200, testClient.getValidConfig(), {
ETag: 'first-etag',
Expand All @@ -307,7 +313,7 @@ describe('Initialize Tests - Local', () => {
let secondConfig: Interceptor
if (hasCapability(sdkName, Capabilities.lastModifiedHeader)) {
secondConfig = scope
.get(testClient.getValidConfigPath())
.get(configRequestUrl)
.matchHeader('If-None-Match', (value) => {
return value === 'first-etag'
})
Expand All @@ -326,7 +332,7 @@ describe('Initialize Tests - Local', () => {
)
} else {
secondConfig = scope
.get(testClient.getValidConfigPath())
.get(configRequestUrl)
.matchHeader('If-None-Match', (value) => {
return value === 'first-etag'
})
Expand Down
3 changes: 2 additions & 1 deletion harness/features/multithreading.local.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
describeCapability,
getSDKScope,
hasCapability,
LocalTestClient,
waitForRequest,
} from '../helpers'
Expand Down Expand Up @@ -36,7 +37,7 @@ describe('Multithreading Tests', () => {
testClient = new LocalTestClient(sdkName)

scope
.get(testClient.getValidConfigPath())
.get(testClient.getValidConfigPath(hasCapability(sdkName, Capabilities.v2Config)))
.reply(200, testClient.getValidConfig(), {
ETag: 'multithreading-etag',
'Cf-Ray': 'multithreading-rayid',
Expand Down
2 changes: 1 addition & 1 deletion harness/features/track.local.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('Track Tests - Local', () => {
user_id: expect.any(String),
type: 'sdkConfig',
target: expect.stringContaining(
client.getValidConfigPath(),
client.getValidConfigPath(hasCapability(sdkName, Capabilities.v2Config)),
),
value: expect.any(Number),
featureVars: {
Expand Down
2 changes: 1 addition & 1 deletion harness/features/variable.local.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('Variable Tests - Local', () => {
// conflicting. This one is used to mock the config that the local client is going to use
// locally in all of its methods.
scope
.get(testClient.getValidConfigPath())
.get(testClient.getValidConfigPath(hasCapability(sdkName, Capabilities.v2Config)))
.reply(200, testClient.getValidConfig(), {
ETag: 'local-var-etag',
'Cf-Ray': 'local-ray-id',
Expand Down
9 changes: 6 additions & 3 deletions harness/helpers/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Interceptor, Scope } from 'nock'
import { SDKCapabilities } from '../types'
import { Capabilities, SDKCapabilities } from '../types'
import { getServerScope, resetServerScope } from '../nock'
import { v4 as uuidv4 } from 'uuid'
import {
Expand Down Expand Up @@ -428,12 +428,15 @@ export class LocalTestClient extends BaseTestClient {
return result
}

getValidConfigPath() {
getValidConfigPath(sendV2 = false) {
if(sendV2) {
return `/client/${this.clientId}/config/v2/server/${this.sdkKey}.json`
}
return `/client/${this.clientId}/config/v1/server/${this.sdkKey}.json`
}

setupMockConfig(scope: Scope) {
scope.get(this.getValidConfigPath()).reply(200, this.getValidConfig())
scope.get(this.getValidConfigPath(hasCapability(this.sdkName, Capabilities.v2Config))).reply(200, this.getValidConfig())
}

getValidConfig() {
Expand Down
2 changes: 2 additions & 0 deletions harness/types/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const Capabilities = {
bootstrapping: 'Bootstrapping',
sdkConfigEvent: 'SDKConfigEvent',
clientUUID: 'ClientUUID',
v2Config: 'V2Config',
}

let sdkCapabilities: { [key: string]: string[] } = {
Expand Down Expand Up @@ -58,6 +59,7 @@ let sdkCapabilities: { [key: string]: string[] } = {
Capabilities.lastModifiedHeader,
Capabilities.sdkConfigEvent,
Capabilities.clientUUID,
//Capabilities.v2Config,
],
Ruby: [Capabilities.clientCustomData],
PHP: [Capabilities.cloudProxy],
Expand Down

0 comments on commit a8843b6

Please sign in to comment.