Skip to content

Commit b84c5b9

Browse files
authored
Merge pull request #42 from contentstack/hotfix/test_cases
Hotfix/test cases
2 parents 1c2ae78 + 8e6b3c4 commit b84c5b9

31 files changed

+58
-43
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 Contentstack
3+
Copyright (c) 2025 Contentstack
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

src/sdk/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,19 @@ export const initializeContentstackSdk = ({
3939
host: host,
4040
branch: branch,
4141
});
42-
} else {
42+
} else if (regionVal) {
4343
Stack = Contentstack.stack({
4444
apiKey: apiKey,
4545
deliveryToken: token,
4646
environment,
4747
region: regionVal,
4848
branch: branch,
4949
});
50+
} else {
51+
throw {
52+
type: "validation",
53+
error_message: `The region "${region}" is not supported and no host is provided for a custom region.`,
54+
};
5055
}
5156

5257
return Stack;

tests/integration/generateTS/generateTS.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe("generateTS function", () => {
2222

2323
expect(generatedTS).toEqual(expect.stringContaining("interface")); // Check for Output is not undefined
2424
expect(generatedTS).toEqual(expect.stringContaining("Dishes")); // Check for whether typeDef of Content type is included
25-
expect(generatedTS).toMatch(/\/\*\*.*\*\/\n\s*(export)/); // Check for is Documentation Generated
25+
expect(generatedTS).toMatch(/\/\*\*[\s\S]*?\*\/\s*(export)/); // Check for Documentation Generated with export
2626
});
2727

2828
it("generates type definitions without Documentation", async () => {
@@ -137,7 +137,9 @@ describe("generateTS function with errors", () => {
137137
branch,
138138
});
139139
} catch (err: any) {
140-
expect(err.error_message).toEqual("Something went wrong");
140+
expect(err.error_message).toEqual(
141+
"Something went wrong while initializing Contentstack SDK."
142+
);
141143
}
142144
});
143145

tests/unit/generateTS/generateTS.test.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ describe("generateTS function with errors", () => {
174174
});
175175

176176
it("Check for Invalid region", async () => {
177-
const token = "your-token";
178-
const apiKey = "your-api-key";
179-
const environment = "development";
180-
const region = "demo" as unknown as any;
181-
const tokenType = "delivery";
182-
const branch = "main";
177+
const token = process.env.TOKEN as unknown as any;
178+
const apiKey = process.env.APIKEY as unknown as any;
179+
const environment = process.env.ENVIRONMENT as unknown as any;
180+
const region = "wrong" as unknown as any;
181+
const tokenType = process.env.TOKENTYPE as unknown as any;
182+
const branch = process.env.BRANCH as unknown as any;
183183

184184
try {
185185
await generateTS({
@@ -191,7 +191,9 @@ describe("generateTS function with errors", () => {
191191
branch,
192192
});
193193
} catch (err: any) {
194-
expect(err.error_message).toEqual("Something went wrong");
194+
expect(err.error_message).toEqual(
195+
"Something went wrong while initializing Contentstack SDK."
196+
);
195197
}
196198
});
197199

@@ -230,7 +232,9 @@ describe("generateTS function with errors", () => {
230232
const tokenType = "delivery";
231233
const branch = "main";
232234

233-
mockClient.onGet(`/content_types`).reply(401);
235+
mockClient.onGet(`/content_types`).reply(401, {
236+
status: 401,
237+
});
234238

235239
try {
236240
await generateTS({
@@ -256,7 +260,9 @@ describe("generateTS function with errors", () => {
256260
const tokenType = "delivery";
257261
const branch = "main";
258262

259-
mockClient.onGet(`/content_types`).reply(401);
263+
mockClient.onGet(`/content_types`).reply(401, {
264+
status: 401,
265+
});
260266

261267
try {
262268
await generateTS({
@@ -342,7 +348,9 @@ describe("generateTS function with errors", () => {
342348

343349
mockClient.onGet(`/content_types`).reply(200, contentTypes);
344350

345-
mockClient.onGet(`/global_fields`).reply(401);
351+
mockClient.onGet(`/global_fields`).reply(401, {
352+
status: 401,
353+
});
346354

347355
try {
348356
await generateTS({

tests/unit/tsgen/boolean.ct.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const builtinBoolean = {
33
updated_at: "2020-07-12T14:37:02.250Z",
44
title: "Boolean",
55
uid: "boolean",
6-
_version: 2,
6+
_version: "number",
77
inbuilt_class: false,
88
schema: [
99
{

tests/unit/tsgen/boolean.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe("builtin boolean field", () => {
2525
"export interface IBoolean
2626
{
2727
/** Version */
28-
_version: 2 ;
28+
_version: number;
2929
title: string ;
3030
boolean?: boolean ;
3131
}"

tests/unit/tsgen/defaults.ct.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const defaultSingleContentBlock = {
33
updated_at: "2020-07-12T13:40:36.124Z",
44
title: "Metadata Single Content Block",
55
uid: "metadata_single_content_block",
6-
_version: 2,
6+
_version: "number",
77
inbuilt_class: false,
88
schema: [
99
{

tests/unit/tsgen/defaults.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe("default single content block", () => {
1818
"export interface IMetadataSingleContentBlock
1919
{
2020
/** Version */
21-
_version: 2 ;
21+
_version: number;
2222
title: string ;
2323
}"
2424
`);
@@ -44,7 +44,7 @@ describe("default single webpage", () => {
4444
"export interface IMetadataSingleWebpage
4545
{
4646
/** Version */
47-
_version: 2 ;
47+
_version: number;
4848
title: string ;
4949
url: string ;
5050
}"

tests/unit/tsgen/global.fields.ct.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const globalFields = {
33
updated_at: "2020-07-12T15:48:52.343Z",
44
title: "Global Fields",
55
uid: "global_fields",
6-
_version: 2,
6+
_version: "number",
77
inbuilt_class: false,
88
schema: [
99
{

tests/unit/tsgen/global.fields.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe("global fields", () => {
2525
"export interface ISeo
2626
{
2727
/** Version */
28-
_version: ;
28+
_version: number;
2929
keywords?: string ;
3030
description?: string ;
3131
}"
@@ -37,7 +37,7 @@ describe("global fields", () => {
3737
"export interface IGlobalFields
3838
{
3939
/** Version */
40-
_version: 2 ;
40+
_version: number;
4141
title: string ;
4242
seo?: ISeo ;
4343
}"

0 commit comments

Comments
 (0)