-
Notifications
You must be signed in to change notification settings - Fork 20
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
31cbb4e
commit fc9f05c
Showing
7 changed files
with
14,747 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
import util from 'util'; | ||
|
||
import { State } from '../shared/State'; | ||
import { | ||
AmConfigEntityInterface, | ||
IdObjectSkeletonInterface, | ||
PagedResult, | ||
} from './ApiTypes'; | ||
import { generateAmApi } from './BaseApi'; | ||
|
||
const scriptTypeURLTemplate = | ||
'%s/json/global-config/services/scripting/contexts/%s'; | ||
const scriptTypesURLTemplate = | ||
'%s/json/global-config/services/scripting/contexts?_queryFilter=true'; | ||
const scriptTypeContextURLTemplate = '%s/json/contexts/%s'; | ||
|
||
const scriptingEngineConfigurationURLTemplate = | ||
scriptTypeURLTemplate + '/engineConfiguration'; | ||
|
||
const apiVersion = 'protocol=2.0,resource=1.0'; | ||
|
||
function getApiConfig() { | ||
return { | ||
apiVersion, | ||
}; | ||
} | ||
|
||
export type ScriptTypeSkeleton = AmConfigEntityInterface & { | ||
defaultScript: string; | ||
languages: string[]; | ||
}; | ||
|
||
export type EngineConfigurationSkeleton = AmConfigEntityInterface & { | ||
blackList: string[]; | ||
coreThreads: number; | ||
idleTimeout: number; | ||
maxThreads: number; | ||
propertyNamePrefix: string; | ||
queueSize: number; | ||
serverTimeout: number; | ||
useSecurityManager: boolean; | ||
whiteList: string[]; | ||
}; | ||
|
||
export type ScriptingContextSkeleton = IdObjectSkeletonInterface & { | ||
allowLists: Record<string, string[]>; | ||
evaluatorVersions: Record<string, string[]>; | ||
}; | ||
|
||
/** | ||
* Get scriptType | ||
* @param {string} scriptTypeId scriptType id | ||
* @returns {Promise<ScriptTypeSkeleton>} a promise that resolves to a scriptType object | ||
*/ | ||
export async function getScriptType({ | ||
scriptTypeId, | ||
state, | ||
}: { | ||
scriptTypeId: string; | ||
state: State; | ||
}): Promise<ScriptTypeSkeleton> { | ||
const urlString = util.format( | ||
scriptTypeURLTemplate, | ||
state.getHost(), | ||
scriptTypeId | ||
); | ||
const { data } = await generateAmApi({ resource: getApiConfig(), state }).get( | ||
urlString, | ||
{ | ||
withCredentials: true, | ||
} | ||
); | ||
return data; | ||
} | ||
|
||
/** | ||
* Get all scriptTypes | ||
* @returns {Promise<PagedResult<ScriptTypeSkeleton[]>>} a promise that resolves to an array of scriptType objects | ||
*/ | ||
export async function getScriptTypes({ | ||
state, | ||
}: { | ||
state: State; | ||
}): Promise<PagedResult<ScriptTypeSkeleton>> { | ||
const urlString = util.format(scriptTypesURLTemplate, state.getHost()); | ||
const { data } = await generateAmApi({ | ||
resource: getApiConfig(), | ||
state, | ||
}).get(urlString, { | ||
withCredentials: true, | ||
}); | ||
return data; | ||
} | ||
|
||
/** | ||
* Get scripting engine configuration | ||
* @param {string} scriptTypeId Script type id | ||
* @returns {Promise<EngineConfigurationSkeleton>} a promise that resolves to an EngineConfigurationSkeleton object | ||
*/ | ||
export async function getScriptingEngineConfiguration({ | ||
scriptTypeId, | ||
state, | ||
}: { | ||
scriptTypeId: string; | ||
state: State; | ||
}): Promise<EngineConfigurationSkeleton> { | ||
const urlString = util.format( | ||
scriptingEngineConfigurationURLTemplate, | ||
state.getHost(), | ||
scriptTypeId | ||
); | ||
const { data } = await generateAmApi({ | ||
resource: getApiConfig(), | ||
state, | ||
}).get(urlString, { | ||
withCredentials: true, | ||
}); | ||
return data; | ||
} | ||
|
||
/** | ||
* Get scripting contexts | ||
* @param {string} scriptTypeId Script type id | ||
* @returns {Promise<ScriptingContextSkeleton>} a promise that resolves to an ScriptingContextSkeleton object | ||
*/ | ||
export async function getScriptingContext({ | ||
scriptTypeId, | ||
state, | ||
}: { | ||
scriptTypeId: string; | ||
state: State; | ||
}): Promise<ScriptingContextSkeleton> { | ||
const urlString = util.format( | ||
scriptTypeContextURLTemplate, | ||
state.getHost(), | ||
scriptTypeId | ||
); | ||
const { data } = await generateAmApi({ | ||
resource: getApiConfig(), | ||
state, | ||
}).get(urlString, { | ||
withCredentials: true, | ||
}); | ||
return data; | ||
} | ||
|
||
/** | ||
* Put script type | ||
* @param {string} scriptTypeId script type id | ||
* @param {ScriptTypeSkeleton} scriptTypeData script type config object | ||
* @returns {Promise<ScriptTypeSkeleton>} a promise that resolves to a script type object | ||
*/ | ||
export async function putScriptType({ | ||
scriptTypeId, | ||
scriptTypeData, | ||
state, | ||
}: { | ||
scriptTypeId: string; | ||
scriptTypeData: ScriptTypeSkeleton; | ||
state: State; | ||
}): Promise<ScriptTypeSkeleton> { | ||
const urlString = util.format( | ||
scriptTypeURLTemplate, | ||
state.getHost(), | ||
scriptTypeId | ||
); | ||
const { data } = await generateAmApi({ | ||
resource: getApiConfig(), | ||
state, | ||
}).put(urlString, scriptTypeData, { | ||
withCredentials: true, | ||
headers: { 'If-Match': '*' }, | ||
}); | ||
return data; | ||
} | ||
|
||
/** | ||
* Put scripting engine configuration | ||
* @param {string} scriptTypeId script type id | ||
* @param {EngineConfigurationSkeleton} engineConfigurationData engine config object | ||
* @returns {Promise<EngineConfigurationSkeleton>} a promise that resolves to a script type object | ||
*/ | ||
export async function putScriptingEngineConfiguration({ | ||
scriptTypeId, | ||
engineConfigurationData, | ||
state, | ||
}: { | ||
scriptTypeId: string; | ||
engineConfigurationData: EngineConfigurationSkeleton; | ||
state: State; | ||
}): Promise<EngineConfigurationSkeleton> { | ||
const urlString = util.format( | ||
scriptingEngineConfigurationURLTemplate, | ||
state.getHost(), | ||
scriptTypeId | ||
); | ||
const { data } = await generateAmApi({ resource: getApiConfig(), state }).put( | ||
urlString, | ||
engineConfigurationData, | ||
{ | ||
withCredentials: true, | ||
} | ||
); | ||
return data; | ||
} |
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,109 @@ | ||
/** | ||
* To record and update snapshots, you must perform 3 steps in order: | ||
* | ||
* 1. Record API responses | ||
* | ||
* To record API responses, you must call the test:record script and | ||
* override all the connection state required to connect to the | ||
* env to record from: | ||
* | ||
* ATTENTION: For the recording to succeed, you MUST make sure to use a | ||
* user account, not a service account. | ||
* | ||
* FRODO_DEBUG=1 FRODO_HOST=frodo-dev npm run test:record ScriptTypeOps | ||
* | ||
* The above command assumes that you have a connection profile for | ||
* 'frodo-dev' on your development machine. | ||
* | ||
* 2. Update snapshots | ||
* | ||
* After recording API responses, you must manually update/create snapshots | ||
* by running: | ||
* | ||
* FRODO_DEBUG=1 npm run test:update ScriptTypeOps | ||
* | ||
* 3. Test your changes | ||
* | ||
* If 1 and 2 didn't produce any errors, you are ready to run the tests in | ||
* replay mode and make sure they all succeed as well: | ||
* | ||
* FRODO_DEBUG=1 npm run test:only ScriptTypeOps | ||
* | ||
* Note: FRODO_DEBUG=1 is optional and enables debug logging for some output | ||
* in case things don't function as expected | ||
*/ | ||
import { autoSetupPolly } from "../utils/AutoSetupPolly"; | ||
import { filterRecording } from "../utils/PollyUtils"; | ||
import * as ScriptTypeOps from "./ScriptTypeOps"; | ||
import { state } from "../lib/FrodoLib"; | ||
|
||
const ctx = autoSetupPolly(); | ||
|
||
describe('ScriptTypeOps', () => { | ||
beforeEach(async () => { | ||
if (process.env.FRODO_POLLY_MODE === 'record') { | ||
ctx.polly.server.any().on('beforePersist', (_req, recording) => { | ||
filterRecording(recording); | ||
}); | ||
} | ||
}); | ||
|
||
describe('createScriptTypeExportTemplate()', () => { | ||
test('0: Method is implemented', async () => { | ||
expect(ScriptTypeOps.createScriptTypeExportTemplate).toBeDefined(); | ||
}); | ||
|
||
test('1: Create ScriptType Export Template', async () => { | ||
const response = ScriptTypeOps.createScriptTypeExportTemplate({ state }); | ||
expect(response).toMatchSnapshot({ | ||
meta: expect.any(Object), | ||
}); | ||
}); | ||
}); | ||
|
||
describe('readScriptType()', () => { | ||
test('0: Method is implemented', async () => { | ||
expect(ScriptTypeOps.readScriptType).toBeDefined(); | ||
}); | ||
//TODO: create tests | ||
}); | ||
|
||
describe('readScriptTypes()', () => { | ||
test('0: Method is implemented', async () => { | ||
expect(ScriptTypeOps.readScriptTypes).toBeDefined(); | ||
}); | ||
|
||
test('1: Read ScriptTypes', async () => { | ||
const response = await ScriptTypeOps.readScriptTypes({ state }); | ||
expect(response).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('exportScriptTypes()', () => { | ||
test('0: Method is implemented', async () => { | ||
expect(ScriptTypeOps.exportScriptTypes).toBeDefined(); | ||
}); | ||
|
||
test('1: Export ScriptTypes', async () => { | ||
const response = await ScriptTypeOps.exportScriptTypes({ state }); | ||
expect(response).toMatchSnapshot({ | ||
meta: expect.any(Object), | ||
}); | ||
}); | ||
}); | ||
|
||
describe('updateScriptType()', () => { | ||
test('0: Method is implemented', async () => { | ||
expect(ScriptTypeOps.updateScriptType).toBeDefined(); | ||
}); | ||
//TODO: create tests | ||
}); | ||
|
||
describe('importScriptTypes()', () => { | ||
test('0: Method is implemented', async () => { | ||
expect(ScriptTypeOps.importScriptTypes).toBeDefined(); | ||
}); | ||
//TODO: create tests | ||
}); | ||
|
||
}); |
Oops, something went wrong.