mirror of
https://github.com/sasjs/adapter.git
synced 2026-04-21 21:21:31 +00:00
refactor(poll-job-state): updated types and func attributes
This commit is contained in:
@@ -7,13 +7,13 @@ import * as uploadTablesModule from '../uploadTables'
|
||||
import * as getTokensModule from '../../../auth/getTokens'
|
||||
import * as formatDataModule from '../../../utils/formatDataForRequest'
|
||||
import * as fetchLogsModule from '../../../utils/fetchLogByChunks'
|
||||
import { PollStrategy } from '../../../types'
|
||||
import { PollOptions } from '../../../types'
|
||||
import { ComputeJobExecutionError, NotFoundError } from '../../../types/errors'
|
||||
import { Logger, LogLevel } from '@sasjs/utils'
|
||||
|
||||
const sessionManager = new (<jest.Mock<SessionManager>>SessionManager)()
|
||||
const requestClient = new (<jest.Mock<RequestClient>>RequestClient)()
|
||||
const defaultPollStrategy: PollStrategy = {
|
||||
const defaultPollOptions: PollOptions = {
|
||||
maxPollCount: 100,
|
||||
pollInterval: 500
|
||||
}
|
||||
@@ -97,7 +97,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -125,7 +125,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
).catch((e: any) => e)
|
||||
|
||||
@@ -151,7 +151,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -175,7 +175,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -201,7 +201,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -247,7 +247,7 @@ describe('executeScript', () => {
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -294,7 +294,7 @@ describe('executeScript', () => {
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
).catch((e: any) => e)
|
||||
|
||||
@@ -314,7 +314,7 @@ describe('executeScript', () => {
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -334,7 +334,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -343,7 +343,7 @@ describe('executeScript', () => {
|
||||
mockJob,
|
||||
false,
|
||||
mockAuthConfig,
|
||||
defaultPollStrategy
|
||||
defaultPollOptions
|
||||
)
|
||||
})
|
||||
|
||||
@@ -364,7 +364,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
).catch((e: any) => e)
|
||||
|
||||
@@ -390,7 +390,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
).catch((e: any) => e)
|
||||
|
||||
@@ -416,7 +416,7 @@ describe('executeScript', () => {
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -441,7 +441,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -467,7 +467,7 @@ describe('executeScript', () => {
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
).catch((e: any) => e)
|
||||
|
||||
@@ -502,7 +502,7 @@ describe('executeScript', () => {
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
).catch((e: any) => e)
|
||||
|
||||
@@ -531,7 +531,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -562,7 +562,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
).catch((e: any) => e)
|
||||
|
||||
@@ -596,7 +596,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -623,7 +623,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
defaultPollStrategy,
|
||||
defaultPollOptions,
|
||||
true
|
||||
).catch((e: any) => e)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import * as saveLogModule from '../saveLog'
|
||||
import * as getFileStreamModule from '../getFileStream'
|
||||
import * as isNodeModule from '../../../utils/isNode'
|
||||
import * as delayModule from '../../../utils/delay'
|
||||
import { PollStrategy, PollStrategies } from '../../../types'
|
||||
import { PollOptions, PollStrategy } from '../../../types'
|
||||
import { WriteStream } from 'fs'
|
||||
|
||||
const baseUrl = 'http://localhost'
|
||||
@@ -15,7 +15,7 @@ const requestClient = new (<jest.Mock<RequestClient>>RequestClient)()
|
||||
requestClient['httpClient'].defaults.baseURL = baseUrl
|
||||
|
||||
const defaultStreamLog = false
|
||||
const defaultPollStrategy: PollStrategy = {
|
||||
const defaultPollStrategy: PollOptions = {
|
||||
maxPollCount: 100,
|
||||
pollInterval: 500
|
||||
}
|
||||
@@ -27,14 +27,10 @@ describe('pollJobState', () => {
|
||||
})
|
||||
|
||||
it('should get valid tokens if the authConfig has been provided', async () => {
|
||||
await pollJobState(
|
||||
requestClient,
|
||||
mockJob,
|
||||
false,
|
||||
mockAuthConfig,
|
||||
defaultPollStrategy,
|
||||
defaultStreamLog
|
||||
)
|
||||
await pollJobState(requestClient, mockJob, false, mockAuthConfig, {
|
||||
...defaultPollStrategy,
|
||||
streamLog: defaultStreamLog
|
||||
})
|
||||
|
||||
expect(getTokensModule.getTokens).toHaveBeenCalledWith(
|
||||
requestClient,
|
||||
@@ -84,14 +80,10 @@ describe('pollJobState', () => {
|
||||
mockSimplePoll()
|
||||
const { saveLog } = require('../saveLog')
|
||||
|
||||
await pollJobState(
|
||||
requestClient,
|
||||
mockJob,
|
||||
false,
|
||||
mockAuthConfig,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
)
|
||||
await pollJobState(requestClient, mockJob, false, mockAuthConfig, {
|
||||
...defaultPollStrategy,
|
||||
streamLog: true
|
||||
})
|
||||
|
||||
expect(saveLog).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
@@ -101,14 +93,10 @@ describe('pollJobState', () => {
|
||||
const { getFileStream } = require('../getFileStream')
|
||||
const { saveLog } = require('../saveLog')
|
||||
|
||||
await pollJobState(
|
||||
requestClient,
|
||||
mockJob,
|
||||
false,
|
||||
mockAuthConfig,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
)
|
||||
await pollJobState(requestClient, mockJob, false, mockAuthConfig, {
|
||||
...defaultPollStrategy,
|
||||
streamLog: true
|
||||
})
|
||||
|
||||
expect(getFileStream).toHaveBeenCalled()
|
||||
expect(saveLog).toHaveBeenCalledTimes(2)
|
||||
@@ -120,14 +108,10 @@ describe('pollJobState', () => {
|
||||
const { saveLog } = require('../saveLog')
|
||||
const { getFileStream } = require('../getFileStream')
|
||||
|
||||
await pollJobState(
|
||||
requestClient,
|
||||
mockJob,
|
||||
false,
|
||||
mockAuthConfig,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
)
|
||||
await pollJobState(requestClient, mockJob, false, mockAuthConfig, {
|
||||
...defaultPollStrategy,
|
||||
streamLog: true
|
||||
})
|
||||
|
||||
expect(getFileStream).not.toHaveBeenCalled()
|
||||
expect(saveLog).not.toHaveBeenCalled()
|
||||
@@ -150,10 +134,10 @@ describe('pollJobState', () => {
|
||||
it('should return the current status when the max poll count is reached', async () => {
|
||||
mockRunningPoll()
|
||||
|
||||
const pollStrategy: PollStrategy = {
|
||||
const pollOptions: PollOptions = {
|
||||
...defaultPollStrategy,
|
||||
maxPollCount: 1,
|
||||
subsequentStrategies: []
|
||||
pollStrategy: []
|
||||
}
|
||||
|
||||
const state = await pollJobState(
|
||||
@@ -161,7 +145,7 @@ describe('pollJobState', () => {
|
||||
mockJob,
|
||||
false,
|
||||
mockAuthConfig,
|
||||
pollStrategy
|
||||
pollOptions
|
||||
)
|
||||
|
||||
expect(state).toEqual('running')
|
||||
@@ -275,19 +259,19 @@ describe('pollJobState', () => {
|
||||
|
||||
const pollIntervals = [3, 4, 5, 6]
|
||||
|
||||
const pollStrategies = [
|
||||
const pollStrategy = [
|
||||
{ maxPollCount: 2, pollInterval: pollIntervals[1] },
|
||||
{ maxPollCount: 3, pollInterval: pollIntervals[2] },
|
||||
{ maxPollCount: 4, pollInterval: pollIntervals[3] }
|
||||
]
|
||||
|
||||
const pollStrategy: PollStrategy = {
|
||||
const pollOptions: PollOptions = {
|
||||
maxPollCount: 1,
|
||||
pollInterval: pollIntervals[0],
|
||||
subsequentStrategies: pollStrategies
|
||||
pollStrategy: pollStrategy
|
||||
}
|
||||
|
||||
await pollJobState(requestClient, mockJob, false, undefined, pollStrategy)
|
||||
await pollJobState(requestClient, mockJob, false, undefined, pollOptions)
|
||||
|
||||
expect(delays).toEqual([pollIntervals[0], ...pollIntervals])
|
||||
})
|
||||
@@ -299,7 +283,7 @@ describe('pollJobState', () => {
|
||||
pollInterval: 3
|
||||
}
|
||||
|
||||
let pollStrategies: PollStrategies = [invalidPollStrategy]
|
||||
let pollStrategy: PollStrategy = [invalidPollStrategy]
|
||||
|
||||
let expectedError = new Error(
|
||||
`Poll strategies are not valid. 'maxPollCount' has to be greater than 0. Invalid poll strategy: \n${JSON.stringify(
|
||||
@@ -312,7 +296,7 @@ describe('pollJobState', () => {
|
||||
await expect(
|
||||
pollJobState(requestClient, mockJob, false, undefined, {
|
||||
...defaultPollStrategy,
|
||||
subsequentStrategies: pollStrategies
|
||||
pollStrategy: pollStrategy
|
||||
})
|
||||
).rejects.toThrow(expectedError)
|
||||
|
||||
@@ -327,7 +311,7 @@ describe('pollJobState', () => {
|
||||
pollInterval: 3
|
||||
}
|
||||
|
||||
pollStrategies = [validPollStrategy, invalidPollStrategy]
|
||||
pollStrategy = [validPollStrategy, invalidPollStrategy]
|
||||
|
||||
expectedError = new Error(
|
||||
`Poll strategies are not valid. 'maxPollCount' has to be greater than 'maxPollCount' in previous poll strategy. Invalid poll strategy: \n${JSON.stringify(
|
||||
@@ -340,7 +324,7 @@ describe('pollJobState', () => {
|
||||
await expect(
|
||||
pollJobState(requestClient, mockJob, false, undefined, {
|
||||
...defaultPollStrategy,
|
||||
subsequentStrategies: pollStrategies
|
||||
pollStrategy: pollStrategy
|
||||
})
|
||||
).rejects.toThrow(expectedError)
|
||||
|
||||
@@ -350,7 +334,7 @@ describe('pollJobState', () => {
|
||||
pollInterval: 0
|
||||
}
|
||||
|
||||
pollStrategies = [invalidPollStrategy]
|
||||
pollStrategy = [invalidPollStrategy]
|
||||
|
||||
expectedError = new Error(
|
||||
`Poll strategies are not valid. 'pollInterval' has to be greater than 0. Invalid poll strategy: \n${JSON.stringify(
|
||||
@@ -363,7 +347,7 @@ describe('pollJobState', () => {
|
||||
await expect(
|
||||
pollJobState(requestClient, mockJob, false, undefined, {
|
||||
...defaultPollStrategy,
|
||||
subsequentStrategies: pollStrategies
|
||||
pollStrategy: pollStrategy
|
||||
})
|
||||
).rejects.toThrow(expectedError)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user