-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,69 @@ | ||
import { test } from '@oclif/test' | ||
import { configHandler } from '@contentstack/cli-utilities' | ||
import * as mock from '../mock/common.mock.json' | ||
import { mock_data } from '../mock/mock2'; | ||
import {test} from "@oclif/test"; | ||
Check warning on line 1 in test/unit/commands/tsgen.test.ts GitHub Actions / build (18.x)
Check failure on line 1 in test/unit/commands/tsgen.test.ts GitHub Actions / build (18.x)
Check failure on line 1 in test/unit/commands/tsgen.test.ts GitHub Actions / build (18.x)
Check warning on line 1 in test/unit/commands/tsgen.test.ts GitHub Actions / build (20.x)
Check failure on line 1 in test/unit/commands/tsgen.test.ts GitHub Actions / build (20.x)
|
||
import {configHandler} from "@contentstack/cli-utilities"; | ||
Check failure on line 2 in test/unit/commands/tsgen.test.ts GitHub Actions / build (18.x)
Check failure on line 2 in test/unit/commands/tsgen.test.ts GitHub Actions / build (18.x)
Check failure on line 2 in test/unit/commands/tsgen.test.ts GitHub Actions / build (20.x)
|
||
import * as mock from "../mock/common.mock.json"; | ||
Check failure on line 3 in test/unit/commands/tsgen.test.ts GitHub Actions / build (18.x)
Check failure on line 3 in test/unit/commands/tsgen.test.ts GitHub Actions / build (18.x)
Check failure on line 3 in test/unit/commands/tsgen.test.ts GitHub Actions / build (20.x)
|
||
const GRAPHQL_REGION_URL_MAPPING = { | ||
na: 'https://graphql.contentstack.com', | ||
us: 'https://graphql.contentstack.com', | ||
eu: 'https://eu-graphql.contentstack.com/stacks', | ||
'azure-na': 'https://azure-na-graphql.contentstack.com/stacks', | ||
'azure-eu': 'https://azure-eu-graphql.contentstack.com/stacks', | ||
} | ||
na: "https://graphql.contentstack.com", | ||
Check failure on line 5 in test/unit/commands/tsgen.test.ts GitHub Actions / build (18.x)
|
||
us: "https://graphql.contentstack.com", | ||
Check failure on line 6 in test/unit/commands/tsgen.test.ts GitHub Actions / build (18.x)
|
||
eu: "https://eu-graphql.contentstack.com/stacks", | ||
Check failure on line 7 in test/unit/commands/tsgen.test.ts GitHub Actions / build (18.x)
|
||
"azure-na": "https://azure-na-graphql.contentstack.com/stacks", | ||
Check failure on line 8 in test/unit/commands/tsgen.test.ts GitHub Actions / build (18.x)
|
||
"azure-eu": "https://azure-eu-graphql.contentstack.com/stacks" | ||
}; | ||
|
||
const region: { cma: string; name: string; cda: string } = configHandler.get('region') | ||
const graphqlUrl: string = region?.name && GRAPHQL_REGION_URL_MAPPING[region.name.toLowerCase() as keyof typeof GRAPHQL_REGION_URL_MAPPING] | ||
const alias = 'token1' | ||
configHandler.set(`tokens.${alias}`, mock.tokens[alias]) | ||
const filePath = './generate1.d.ts' | ||
const region: { cma: string; name: string; cda: string } = | ||
configHandler.get("region"); | ||
const graphqlUrl: string = | ||
region?.name && | ||
GRAPHQL_REGION_URL_MAPPING[ | ||
region.name.toLowerCase() as keyof typeof GRAPHQL_REGION_URL_MAPPING | ||
]; | ||
const alias = "token1"; | ||
configHandler.set(`tokens.${alias}`, mock.tokens[alias]); | ||
const filePath = "./generate1.d.ts"; | ||
|
||
|
||
describe('Tsgen command', () => { | ||
describe('Graphql type generator', () => { | ||
describe("Tsgen command", () => { | ||
describe("Graphql type generator", () => { | ||
test | ||
.stdout({ print: process.env.PRINT === 'true' || false }) | ||
.nock(graphqlUrl, api => | ||
.stdout({ print: process.env.PRINT === "true" || false }) | ||
.nock(graphqlUrl, (api) => | ||
api | ||
.post(`/stacks/${mock.tokens[alias].apiKey}?environment=development`) | ||
.reply(200, { | ||
data: mock_data, | ||
data: mock.mock_data | ||
}) | ||
) | ||
.command(['tsgen', '--token-alias', alias, '--output', filePath, '--api-type', 'graphql']) | ||
.it('should generate a type def for graphql query') | ||
}) | ||
.command([ | ||
"tsgen", | ||
"--token-alias", | ||
alias, | ||
"--output", | ||
filePath, | ||
"--api-type", | ||
"graphql" | ||
]) | ||
.it("should generate a type def for graphql query"); | ||
}); | ||
|
||
describe('Graphql type generator with namespace', () => { | ||
describe("Graphql type generator with namespace", () => { | ||
test | ||
.stdout({ print: process.env.PRINT === 'true' || false }) | ||
.nock(graphqlUrl, api => | ||
.stdout({ print: process.env.PRINT === "true" || false }) | ||
.nock(graphqlUrl, (api) => | ||
api | ||
.post(`/stacks/${mock.tokens[alias].apiKey}?environment=development`) | ||
.reply(200, { | ||
data: mock_data, | ||
data: mock.mock_data | ||
}) | ||
) | ||
.command(['tsgen', '--api-type', 'graphql', '-a', alias, '--output', filePath, '--namespace', 'GraphQL']) | ||
.it('should generate a type def for graphql query with namespace') | ||
}) | ||
}) | ||
.command([ | ||
"tsgen", | ||
"--api-type", | ||
"graphql", | ||
"-a", | ||
alias, | ||
"--output", | ||
filePath, | ||
"--namespace", | ||
"GraphQL" | ||
]) | ||
.it("should generate a type def for graphql query with namespace"); | ||
}); | ||
}); |