-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from celonis/TA-2683-testing
[TA-2683] Setup tests and add tests for listing assignments
- Loading branch information
Showing
11 changed files
with
2,063 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,5 @@ jobs: | |
run: yarn install | ||
- name: Yarn Build | ||
run: yarn build | ||
- name: Yarn Test | ||
run: yarn test |
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,16 @@ | ||
import type { Config } from "@jest/types" | ||
const config: Config.InitialOptions = { | ||
verbose: true, | ||
transform: { | ||
"^.+\\.tsx?$": "ts-jest", | ||
}, | ||
testMatch: ["<rootDir>/tests/**/*.spec.ts"], | ||
moduleNameMapper: { | ||
"^\\./../package.json$": "<rootDir>/tests/mocks/package.json", | ||
}, | ||
setupFilesAfterEnv: [ | ||
"<rootDir>/tests/jest.setup.ts", | ||
], | ||
} | ||
|
||
export default config |
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,25 @@ | ||
import * as fs from 'fs'; | ||
import {setDefaultProfile} from "./utls/context-mock"; | ||
import {TestTransport} from "./utls/test-transport"; | ||
import {logger} from "../src/util/logger"; | ||
|
||
// Mock the modules using Jest | ||
jest.mock('axios'); | ||
jest.mock('fs'); | ||
|
||
(fs.writeFileSync as jest.Mock).mockImplementation(() => { | ||
// Mock implementation here if needed | ||
}); | ||
|
||
beforeAll(() => { | ||
setDefaultProfile(); | ||
}) | ||
|
||
let testTransport; | ||
|
||
beforeEach(() => { | ||
testTransport = new TestTransport({}) | ||
logger.add(testTransport); | ||
}) | ||
|
||
export {testTransport}; |
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,66 @@ | ||
import {VariableCommand} from "../../src/commands/variable.command"; | ||
import axios from "axios"; | ||
import {FileService} from "../../src/services/file-service"; | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import {testTransport} from "../jest.setup"; | ||
|
||
describe("List assignments", () => { | ||
|
||
it("Should list assignments for supported type and non-json response", async () => { | ||
const mockAssignmentValues = [ | ||
{id: "id-1"}, | ||
{id: "id-2"} | ||
]; | ||
const resp = {data: mockAssignmentValues}; | ||
(axios.get as jest.Mock).mockResolvedValue(resp); | ||
|
||
await new VariableCommand().listAssignments("DATA_MODEL", false, ""); | ||
|
||
expect(testTransport.logMessages.length).toBe(2); | ||
expect(testTransport.logMessages[0].message).toContain('{"id":"id-1"}'); | ||
expect(testTransport.logMessages[1].message).toContain('{"id":"id-2"}'); | ||
|
||
expect(axios.get).toHaveBeenCalledWith("https://myTeam.celonis.cloud/package-manager/api/compute-pools/pools-with-data-models", expect.anything()) | ||
}) | ||
|
||
it("Should export assignments for supported type and json response", async () => { | ||
const mockAssignmentValues = [ | ||
{id: "id-1"}, | ||
{id: "id-2"} | ||
]; | ||
const resp = {data: mockAssignmentValues}; | ||
(axios.get as jest.Mock).mockResolvedValue(resp); | ||
|
||
await new VariableCommand().listAssignments("DATA_MODEL", true, ""); | ||
|
||
expect(testTransport.logMessages.length).toBe(1); | ||
expect(testTransport.logMessages[0].message).toContain(FileService.fileDownloadedMessage); | ||
|
||
const expectedFileName = testTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1]; | ||
|
||
expect(fs.writeFileSync).toHaveBeenCalledWith(path.resolve(process.cwd(), expectedFileName), JSON.stringify(mockAssignmentValues), {encoding: "utf-8"}); | ||
}) | ||
|
||
it("Should contain url params in the url", async () => { | ||
const mockAssignmentValues = [{id: "id-1"}]; | ||
const resp = {data: mockAssignmentValues}; | ||
(axios.get as jest.Mock).mockResolvedValue(resp); | ||
|
||
await new VariableCommand().listAssignments("CONNECTION", false, "param1=value1,param2=value2"); | ||
|
||
expect(axios.get).toHaveBeenCalledWith("https://myTeam.celonis.cloud/process-automation-v2/api/connections?param1=value1¶m2=value2", expect.anything()) | ||
}) | ||
|
||
it("Should throw error for unsupported variable types", async () => { | ||
const type: string = "DUMMY_UNSUPPORTED_TYPE"; | ||
|
||
try { | ||
await new VariableCommand().listAssignments(type, false, ""); | ||
} catch (e) { | ||
if (!(e.message === `Variable type ${type} not supported.`)) { | ||
fail(); | ||
} | ||
} | ||
}) | ||
}) |
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,3 @@ | ||
{ | ||
"version": "mocked-version" | ||
} |
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,12 @@ | ||
import {contextService} from "../../src/services/context.service"; | ||
|
||
export function setDefaultProfile(): void { | ||
contextService.setContext({ | ||
profile: { | ||
name: "test", | ||
team: "https://myTeam.celonis.cloud/", | ||
apiToken: "YnQ3N2M0M2ItYzQ3OS00YzgyLTg0ODgtOWNkNzhiNzYwOTU2OlFkNnBpVCs0M0JBYm1ZWGlCZ2hPd245aldwWTNubFQyYVFOTFBUeHEwdUxM", | ||
authenticationType: "Bearer" | ||
} | ||
}); | ||
} |
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,15 @@ | ||
import * as Transport from "winston-transport"; | ||
import {LogEntry} from "winston"; | ||
|
||
export class TestTransport extends Transport { | ||
public logMessages: LogEntry[] = []; | ||
|
||
constructor(options: any) { | ||
super(options); | ||
} | ||
|
||
public log(info: LogEntry, callback: () => void): void { | ||
this.logMessages.push(info); | ||
callback(); | ||
} | ||
} |
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
Oops, something went wrong.