-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: return error if the namespace doesnt exist while listing graphs (#…
- Loading branch information
1 parent
ba52250
commit 3bc8035
Showing
5 changed files
with
461 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
controlplane/test/feature-flag/get-feature-flags.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb'; | ||
import { afterAll, beforeAll, describe, expect, test } from 'vitest'; | ||
import { afterAllSetup, beforeAllSetup, genID, genUniqueLabel } from '../../src/core/test-util.js'; | ||
import { | ||
DEFAULT_SUBGRAPH_URL_ONE, | ||
DEFAULT_SUBGRAPH_URL_TWO, | ||
SetupTest, | ||
createBaseAndFeatureSubgraph, | ||
} from '../test-util.js'; | ||
|
||
let dbname = ''; | ||
|
||
describe('List feature flags', (ctx) => { | ||
beforeAll(async () => { | ||
dbname = await beforeAllSetup(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await afterAllSetup(dbname); | ||
}); | ||
|
||
test('Should be able to list feature flags of different namespace', async (testContext) => { | ||
const { client, server } = await SetupTest({ dbname }); | ||
|
||
const subgraphName = genID('subgraph'); | ||
const featureSubgraphName = genID('featureSubgraph'); | ||
const flagName = genID('flag'); | ||
|
||
const createNamespaceResp = await client.createNamespace({ | ||
name: 'prod', | ||
}); | ||
|
||
expect(createNamespaceResp.response?.code).toBe(EnumStatusCode.OK); | ||
|
||
await createBaseAndFeatureSubgraph( | ||
client, | ||
subgraphName, | ||
featureSubgraphName, | ||
DEFAULT_SUBGRAPH_URL_ONE, | ||
DEFAULT_SUBGRAPH_URL_TWO, | ||
); | ||
|
||
await createBaseAndFeatureSubgraph( | ||
client, | ||
subgraphName, | ||
featureSubgraphName, | ||
DEFAULT_SUBGRAPH_URL_ONE, | ||
DEFAULT_SUBGRAPH_URL_TWO, | ||
'prod', | ||
); | ||
|
||
let featureFlagResponse = await client.createFeatureFlag({ | ||
name: flagName, | ||
featureSubgraphNames: [featureSubgraphName], | ||
isEnabled: true, | ||
}); | ||
|
||
expect(featureFlagResponse.response?.code).toBe(EnumStatusCode.OK); | ||
|
||
featureFlagResponse = await client.createFeatureFlag({ | ||
name: flagName, | ||
featureSubgraphNames: [featureSubgraphName], | ||
namespace: 'prod', | ||
isEnabled: true, | ||
}); | ||
|
||
expect(featureFlagResponse.response?.code).toBe(EnumStatusCode.OK); | ||
|
||
// fetching feature flags from default namespace | ||
let listFeatureFlagsResp = await client.getFeatureFlags({ | ||
namespace: 'default', | ||
offset: 0, | ||
// fetches all | ||
limit: 0, | ||
}); | ||
|
||
expect(listFeatureFlagsResp.response?.code).toBe(EnumStatusCode.OK); | ||
expect(listFeatureFlagsResp.totalCount).toBe(1); | ||
|
||
// fetching feature flags from prod namespace | ||
listFeatureFlagsResp = await client.getFeatureFlags({ | ||
namespace: 'prod', | ||
offset: 0, | ||
// fetches all | ||
limit: 0, | ||
}); | ||
|
||
expect(listFeatureFlagsResp.response?.code).toBe(EnumStatusCode.OK); | ||
expect(listFeatureFlagsResp.totalCount).toBe(1); | ||
|
||
// fetching all feature flags | ||
listFeatureFlagsResp = await client.getFeatureFlags({ | ||
offset: 0, | ||
// fetches all | ||
limit: 0, | ||
}); | ||
|
||
expect(listFeatureFlagsResp.response?.code).toBe(EnumStatusCode.OK); | ||
expect(listFeatureFlagsResp.totalCount).toBe(2); | ||
|
||
// fetching feature flags from non-existing namespace | ||
listFeatureFlagsResp = await client.getFeatureFlags({ | ||
// prod1 namespace does not exist | ||
namespace: 'prod1', | ||
offset: 0, | ||
// fetches all | ||
limit: 0, | ||
}); | ||
|
||
expect(listFeatureFlagsResp.response?.code).toBe(EnumStatusCode.ERR_NOT_FOUND); | ||
expect(listFeatureFlagsResp.response?.details).toBe(`Could not find namespace prod1`); | ||
|
||
await server.close(); | ||
}); | ||
}); |
98 changes: 98 additions & 0 deletions
98
controlplane/test/feature-subgraph/get-feature-subgraphs.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb'; | ||
import { afterAll, beforeAll, describe, expect, test } from 'vitest'; | ||
import { afterAllSetup, beforeAllSetup, genID } from '../../src/core/test-util.js'; | ||
import { | ||
DEFAULT_SUBGRAPH_URL_ONE, | ||
DEFAULT_SUBGRAPH_URL_TWO, | ||
SetupTest, | ||
createBaseAndFeatureSubgraph, | ||
} from '../test-util.js'; | ||
|
||
let dbname = ''; | ||
|
||
describe('List feature subgraphs', (ctx) => { | ||
beforeAll(async () => { | ||
dbname = await beforeAllSetup(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await afterAllSetup(dbname); | ||
}); | ||
|
||
test('Should be able to list feature subgraphs of different namespace', async (testContext) => { | ||
const { client, server } = await SetupTest({ dbname }); | ||
|
||
const subgraphName = genID('subgraph'); | ||
const featureSubgraphName = genID('featureSubgraph'); | ||
const flagName = genID('flag'); | ||
|
||
const createNamespaceResp = await client.createNamespace({ | ||
name: 'prod', | ||
}); | ||
|
||
expect(createNamespaceResp.response?.code).toBe(EnumStatusCode.OK); | ||
|
||
await createBaseAndFeatureSubgraph( | ||
client, | ||
subgraphName, | ||
featureSubgraphName, | ||
DEFAULT_SUBGRAPH_URL_ONE, | ||
DEFAULT_SUBGRAPH_URL_TWO, | ||
); | ||
|
||
await createBaseAndFeatureSubgraph( | ||
client, | ||
subgraphName, | ||
featureSubgraphName, | ||
DEFAULT_SUBGRAPH_URL_ONE, | ||
DEFAULT_SUBGRAPH_URL_TWO, | ||
'prod', | ||
); | ||
|
||
// fetching feature subgraphs from default namespace | ||
let listFeatureSubgraphsResp = await client.getFeatureSubgraphs({ | ||
namespace: 'default', | ||
offset: 0, | ||
// fetches all | ||
limit: 0, | ||
}); | ||
|
||
expect(listFeatureSubgraphsResp.response?.code).toBe(EnumStatusCode.OK); | ||
expect(listFeatureSubgraphsResp.count).toBe(1); | ||
|
||
// fetching feature subgraphs from prod namespace | ||
listFeatureSubgraphsResp = await client.getFeatureSubgraphs({ | ||
namespace: 'prod', | ||
offset: 0, | ||
// fetches all | ||
limit: 0, | ||
}); | ||
|
||
expect(listFeatureSubgraphsResp.response?.code).toBe(EnumStatusCode.OK); | ||
expect(listFeatureSubgraphsResp.count).toBe(1); | ||
|
||
// fetching all feature subgraphs | ||
listFeatureSubgraphsResp = await client.getFeatureSubgraphs({ | ||
offset: 0, | ||
// fetches all | ||
limit: 0, | ||
}); | ||
|
||
expect(listFeatureSubgraphsResp.response?.code).toBe(EnumStatusCode.OK); | ||
expect(listFeatureSubgraphsResp.count).toBe(2); | ||
|
||
// fetching feature subgraphs from non-existing namespace | ||
listFeatureSubgraphsResp = await client.getFeatureSubgraphs({ | ||
// prod1 namespace does not exist | ||
namespace: 'prod1', | ||
offset: 0, | ||
// fetches all | ||
limit: 0, | ||
}); | ||
|
||
expect(listFeatureSubgraphsResp.response?.code).toBe(EnumStatusCode.ERR_NOT_FOUND); | ||
expect(listFeatureSubgraphsResp.response?.details).toBe(`Could not find namespace prod1`); | ||
|
||
await server.close(); | ||
}); | ||
}); |
Oops, something went wrong.