Skip to content

Commit

Permalink
fixed current test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
cs-raj committed Sep 25, 2024
1 parent a6c6791 commit f8e413b
Show file tree
Hide file tree
Showing 3 changed files with 5,523 additions and 80 deletions.
52 changes: 26 additions & 26 deletions test/unit/commands/tsgen.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {test} from '@oclif/test'
import {configHandler} from '@contentstack/cli-utilities'

import { test } from '@oclif/test'

Check warning on line 1 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Definition for rule 'unicorn/prefer-module' was not found

Check failure on line 1 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

There should be no space after '{'

Check failure on line 1 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

There should be no space before '}'

Check warning on line 1 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Definition for rule 'unicorn/prefer-module' was not found

Check failure on line 1 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

There should be no space after '{'

Check failure on line 1 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

There should be no space before '}'
import { configHandler } from '@contentstack/cli-utilities'

Check failure on line 2 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

There should be no space after '{'

Check failure on line 2 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

There should be no space before '}'

Check failure on line 2 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

There should be no space after '{'

Check failure on line 2 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

There should be no space before '}'
import * as mock from '../mock/common.mock.json'

import { mock_data } from '../mock/mock2';

Check failure on line 4 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

There should be no space after '{'

Check failure on line 4 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

There should be no space before '}'

Check failure on line 4 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Extra semicolon

Check failure on line 4 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

There should be no space after '{'

Check failure on line 4 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

There should be no space before '}'

Check failure on line 4 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Extra semicolon
const GRAPHQL_REGION_URL_MAPPING = {
na: 'https://graphql.contentstack.com',
us: 'https://graphql.contentstack.com',
Expand All @@ -12,37 +11,38 @@ const GRAPHQL_REGION_URL_MAPPING = {
}

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 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])
configHandler.set(`tokens.${alias}`, mock.tokens[alias])
const filePath = './generate1.d.ts'

Check failure on line 18 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

More than 1 blank line not allowed

Check failure on line 18 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

More than 1 blank line not allowed

describe('Tsgen command', () => {
describe('Graphql type generator', () => {
test
.stdout({print: process.env.PRINT === 'true' || false})
.nock(graphqlUrl, api =>
api
.post(`/stacks/${mock.tokens[alias].apiKey}`)
.reply(200, {
data: mock.output,
})
)
.command(['tsgen', '--token-alias', alias, '--output', filePath, '--api-type', 'graphql'])
.it('should generate a type def for graphql query')
.stdout({ print: process.env.PRINT === 'true' || false })

Check failure on line 23 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 4 spaces but found 6

Check failure on line 23 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

There should be no space after '{'

Check failure on line 23 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected indentation of 4 spaces but found 6

Check failure on line 23 in test/unit/commands/tsgen.test.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

There should be no space after '{'
.nock(graphqlUrl, api =>
api
.post(`/stacks/${mock.tokens[alias].apiKey}?environment=development`)
.reply(200, {
data: mock_data,
})
)
.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', () => {
test
.stdout({print: process.env.PRINT === 'true' || false})
.nock(graphqlUrl, api =>
api
.post(`/stacks/${mock.tokens[alias].apiKey}`)
.reply(200, {
data: mock.output,
})
)
.command(['tsgen', '--api-type', 'graphql', '-a', alias, '--output', filePath, '--namespace', 'GraphQL'])
.it('should generate a type def for graphql query with namespace')
.stdout({ print: process.env.PRINT === 'true' || false })
.nock(graphqlUrl, api =>
api
.post(`/stacks/${mock.tokens[alias].apiKey}?environment=development`)
.reply(200, {
data: mock_data,
})
)
.command(['tsgen', '--api-type', 'graphql', '-a', alias, '--output', filePath, '--namespace', 'GraphQL'])
.it('should generate a type def for graphql query with namespace')
})
})
54 changes: 0 additions & 54 deletions test/unit/mock/common.mock.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,6 @@
"api_key": "stack_api_key_1"
}
],
"output": {
"data": {
"__schema": {
"queryType": { "name": "Query" },
"mutationType": null,
"subscriptionType": null,
"types": [
{
"kind": "OBJECT",
"name": "SysAsset",
"description": null,
"fields": [
{
"name": "title",
"description": null,
"args": [],
"type": [],
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "url",
"description": null,
"args": [],
"type": [],
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "content_type",
"description": null,
"args": [],
"type": [],
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
}
],
"directives": [
{
"name": "include",
"description": "Directs the executor to include this field or fragment only when the `if` argument is true.",
"locations": ["FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"],
"args": [[]]
}
]
}
}
},
"tokens": {
"token1": {
"token": "test_token",
Expand Down
Loading

0 comments on commit f8e413b

Please sign in to comment.