-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38ebd33
commit 395917c
Showing
5 changed files
with
474 additions
and
112 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
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
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,268 @@ | ||
import { generateTS } from "../../../src/generateTS/index"; | ||
const dotenv = require("dotenv"); | ||
dotenv.config({ path: "../../../.env" }); | ||
|
||
describe("generateTS function", () => { | ||
it("generates type definitions", async () => { | ||
const token = process.env.TOKEN as unknown as any; | ||
const apiKey = process.env.APIKEY as unknown as any; | ||
const environment = process.env.ENVIRONMENT as unknown as any; | ||
const region = process.env.REGION as unknown as any; | ||
const tokenType = process.env.TOKENTYPE as unknown as any; | ||
const branch = process.env.BRANCH as unknown as any; | ||
|
||
const generatedTS = await generateTS({ | ||
token, | ||
apiKey, | ||
environment, | ||
region, | ||
tokenType, | ||
branch, | ||
}); | ||
|
||
expect(generatedTS).toEqual(expect.stringContaining("interface")); // Check for Output is not undefined | ||
expect(generatedTS).toEqual(expect.stringContaining("Dishes")); // Check for whether typeDef of Content type is included | ||
expect(generatedTS).toEqual(expect.stringContaining("Seo")); // Check for whether typeDef of Global Fields is included | ||
expect(generatedTS).toMatch(/\/\*\*.*\*\/\n\s*(export)/); // Check for is Documentation Generated | ||
}); | ||
|
||
it("generates type definitions without Documentation", async () => { | ||
const token = process.env.TOKEN as unknown as any; | ||
const apiKey = process.env.APIKEY as unknown as any; | ||
const environment = process.env.ENVIRONMENT as unknown as any; | ||
const region = process.env.REGION as unknown as any; | ||
const tokenType = process.env.TOKENTYPE as unknown as any; | ||
const includeDocumentation = false; | ||
|
||
const generatedTS = await generateTS({ | ||
token, | ||
apiKey, | ||
environment, | ||
region, | ||
tokenType, | ||
includeDocumentation, | ||
}); | ||
|
||
expect(generatedTS).toEqual(expect.stringContaining("interface")); // Check for Output is not undefined | ||
expect(generatedTS).toEqual(expect.stringContaining("Dishes")); // Check for whether typeDef of Content type is included | ||
expect(generatedTS).toEqual(expect.stringContaining("Seo")); // Check for whether typeDef of Global Fields is included | ||
expect(generatedTS).not.toMatch(/\/\*\*.*\*\/\n\s*(export)/); // Check for No Documentation is generated | ||
}); | ||
|
||
it("generates type definitions with prefix", async () => { | ||
const token = process.env.TOKEN as unknown as any; | ||
const apiKey = process.env.APIKEY as unknown as any; | ||
const environment = process.env.ENVIRONMENT as unknown as any; | ||
const region = process.env.REGION as unknown as any; | ||
const tokenType = process.env.TOKENTYPE as unknown as any; | ||
const prefix = "test"; | ||
|
||
const generatedTS = await generateTS({ | ||
token, | ||
apiKey, | ||
environment, | ||
region, | ||
tokenType, | ||
prefix, | ||
}); | ||
|
||
expect(generatedTS).toEqual(expect.stringContaining("interface")); // Check for Output is not undefined | ||
expect(generatedTS).toMatch(/(?!Dishes)testDishes/); // Check for whether typeDef of Content type is included with test prefix | ||
expect(generatedTS).toMatch(/(?!Seo)testSeo/); // Check for whether typeDef of Global Fields is included with test prefix | ||
expect(generatedTS).toMatch(/\/\*\*.*\*\/\n\s*(export)/); // Check for Documentation is generated | ||
}); | ||
|
||
it("generates type definitions with system fields", async () => { | ||
const token = process.env.TOKEN as unknown as any; | ||
const apiKey = process.env.APIKEY as unknown as any; | ||
const environment = process.env.ENVIRONMENT as unknown as any; | ||
const region = process.env.REGION as unknown as any; | ||
const tokenType = process.env.TOKENTYPE as unknown as any; | ||
const systemFields = true; | ||
|
||
const generatedTS = await generateTS({ | ||
token, | ||
apiKey, | ||
environment, | ||
region, | ||
tokenType, | ||
systemFields, | ||
}); | ||
|
||
expect(generatedTS).toEqual(expect.stringContaining("interface")); // Check for Output is not undefined | ||
expect(generatedTS).toMatch(/Dishes/); // Check for whether typeDef of Content type is included | ||
expect(generatedTS).toMatch(/Seo/); // Check for whether typeDef of Global Fields is included | ||
expect(generatedTS).toMatch(/export interface SystemFields \{\n/); // Check for whether System Fields are Created | ||
expect(generatedTS).toMatch(/extends SystemFields \{\n/); // Check for whether interfaces have extended system fields interface | ||
expect(generatedTS).toMatch(/\/\*\*.*\*\/\n\s*(export)/); // Check for Documentation is generated | ||
}); | ||
}); | ||
|
||
describe("generateTS function with errors", () => { | ||
it("Check for if all the required fields are provided", async () => { | ||
const token = ""; | ||
const apiKey = process.env.APIKEY as unknown as any; | ||
const environment = process.env.ENVIRONMENT as unknown as any; | ||
const region = process.env.REGION as unknown as any; | ||
const tokenType = process.env.TOKENTYPE as unknown as any; | ||
const branch = process.env.BRANCH as unknown as any; | ||
|
||
try { | ||
await generateTS({ | ||
token, | ||
apiKey, | ||
environment, | ||
region, | ||
tokenType, | ||
branch, | ||
}); | ||
} catch (err: any) { | ||
expect(err.error_message).toEqual( | ||
"Please provide all the required params (token, tokenType, apiKey, environment, region)" | ||
); | ||
} | ||
}); | ||
|
||
it("Check for Invalid region", async () => { | ||
const token = process.env.TOKEN as unknown as any; | ||
const apiKey = process.env.APIKEY as unknown as any; | ||
const environment = process.env.ENVIRONMENT as unknown as any; | ||
const region = "wrong" as unknown as any; | ||
const tokenType = process.env.TOKENTYPE as unknown as any; | ||
const branch = process.env.BRANCH as unknown as any; | ||
|
||
try { | ||
await generateTS({ | ||
token, | ||
apiKey, | ||
environment, | ||
region, | ||
tokenType, | ||
branch, | ||
}); | ||
} catch (err: any) { | ||
expect(err.error_message).toEqual( | ||
"Please provide a valid region, supported regions are : (US, EU, AZURE_NA, AZURE_EU, GCP_NA)" | ||
); | ||
} | ||
}); | ||
|
||
it("Check for empty content-type response", async () => { | ||
const token = process.env.TOKEN_WITH_NO_CT as unknown as any; | ||
const apiKey = process.env.APIKEY_WITH_NO_CT as unknown as any; | ||
const environment = process.env.ENVIRONMENT as unknown as any; | ||
const region = process.env.REGION as unknown as any; | ||
const tokenType = process.env.TOKENTYPE as unknown as any; | ||
const branch = process.env.BRANCH as unknown as any; | ||
|
||
try { | ||
await generateTS({ | ||
token, | ||
apiKey, | ||
environment, | ||
region, | ||
tokenType, | ||
branch, | ||
}); | ||
} catch (err: any) { | ||
expect(err.error_message).toEqual( | ||
"There are no Content Types in the Stack, please create Content Models to generate type definitions" | ||
); | ||
} | ||
}); | ||
|
||
// it("Check for invalid api_key", async () => { | ||
// const token = process.env.TOKEN as unknown as any; | ||
// const apiKey = "process.env.APIKEY" as unknown as any; | ||
// const environment = process.env.ENVIRONMENT as unknown as any; | ||
// const region = process.env.REGION as unknown as any; | ||
// const tokenType = process.env.TOKENTYPE as unknown as any; | ||
// const branch = process.env.BRANCH as unknown as any; | ||
|
||
// try { | ||
// await generateTS({ | ||
// token, | ||
// apiKey, | ||
// environment, | ||
// region, | ||
// tokenType, | ||
// branch, | ||
// }); | ||
// } catch (err: any) { | ||
// expect(err.error_message).toEqual( | ||
// "Invalid Credentials: Please check the provided apiKey, token and region." | ||
// ); | ||
// } | ||
// }); | ||
|
||
// it("Check for invalid delivery token", async () => { | ||
// const token = "csqw046a21crf2152b87d64r" as unknown as any; | ||
// const apiKey = process.env.APIKEY as unknown as any; | ||
// const environment = process.env.ENVIRONMENT as unknown as any; | ||
// const region = process.env.REGION as unknown as any; | ||
// const tokenType = process.env.TOKENTYPE as unknown as any; | ||
// const branch = process.env.BRANCH as unknown as any; | ||
|
||
// try { | ||
// await generateTS({ | ||
// token, | ||
// apiKey, | ||
// environment, | ||
// region, | ||
// tokenType, | ||
// branch, | ||
// }); | ||
// } catch (err: any) { | ||
// expect(err.error_message).toEqual( | ||
// "Unauthorized: The apiKey, token or region is not valid." | ||
// ); | ||
// } | ||
// }); | ||
|
||
// // Branch Support is Not there in TS SDK | ||
// it("Check for default error with invalid branch", async () => { | ||
// const token = process.env.TOKEN as unknown as any; | ||
// const apiKey = process.env.APIKEY as unknown as any; | ||
// const environment = process.env.ENVIRONMENT as unknown as any; | ||
// const region = process.env.REGION as unknown as any; | ||
// const tokenType = process.env.TOKENTYPE as unknown as any; | ||
// const branch = "mai" as unknown as any; | ||
|
||
// try { | ||
// await generateTS({ | ||
// token, | ||
// apiKey, | ||
// environment, | ||
// region, | ||
// tokenType, | ||
// branch, | ||
// }); | ||
// } catch (err: any) { | ||
// expect(err.error_message).toEqual( | ||
// "Something went wrong, Access denied. You have insufficient permissions to perform operation on this branch 'mai'." | ||
// ); | ||
// } | ||
// }); | ||
|
||
// it("Check for default error like Bad-Request", async () => { | ||
// const token = "process.env.TOKEN" as unknown as any; | ||
// const apiKey = process.env.APIKEY as unknown as any; | ||
// const environment = process.env.ENVIRONMENT as unknown as any; | ||
// const region = process.env.REGION as unknown as any; | ||
// const tokenType = process.env.TOKENTYPE as unknown as any; | ||
// const branch = process.env.BRANCH as unknown as any; | ||
|
||
// try { | ||
// await generateTS({ | ||
// token, | ||
// apiKey, | ||
// environment, | ||
// region, | ||
// tokenType, | ||
// branch, | ||
// }); | ||
// } catch (err: any) { | ||
// expect(err.error_message).toEqual("Something went wrong, Bad Request"); | ||
// } | ||
// }); | ||
}); |
Oops, something went wrong.