generated from hideokamoto/my-ts-project-template
-
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
754c8c9
commit efa03f1
Showing
3 changed files
with
74 additions
and
4 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
docs/ | ||
examples/ | ||
__tests__/ |
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 |
---|---|---|
@@ -1,8 +1,76 @@ | ||
|
||
import func from '../libs/index' | ||
import CloudFrontUpdator, { | ||
interfaces | ||
} from '../libs/index' | ||
|
||
const condition: interfaces.Config = { | ||
debugMode: true, | ||
taskType: 'parallel', | ||
allowSensitiveAction: false | ||
} | ||
class DummyClient { | ||
// @ts-ignore | ||
getDistributionConfig (param: any) { | ||
return { | ||
promise (): AWS.CloudFront.GetDistributionConfigResult { | ||
const DistributionConfig: AWS.CloudFront.DistributionConfig = { | ||
Enabled: true | ||
} as AWS.CloudFront.DistributionConfig | ||
return { | ||
ETag: 'tag', | ||
DistributionConfig | ||
} | ||
} | ||
} | ||
} | ||
|
||
// @ts-ignore | ||
updateDistribution (param: any) { | ||
return { | ||
promise () { | ||
return {} | ||
} | ||
} | ||
} | ||
|
||
// @ts-ignore | ||
listDistributions (param: any) { | ||
return { | ||
promise () { | ||
return {} | ||
} | ||
} | ||
} | ||
} | ||
describe('dummy', () => { | ||
it('test', () => { | ||
expect(func('John')).toEqual('Hello John !') | ||
// @ts-ignore | ||
const updator: interfaces.UpdatorFunction = (id, conf) => conf | ||
const filter: interfaces.FilterCondition = () => true | ||
let client = new CloudFrontUpdator({ | ||
updator, | ||
filter | ||
}, condition, { | ||
cfClient: new DummyClient() as any as AWS.CloudFront | ||
}) | ||
it('should work', async () => { | ||
const dist = {} as AWS.CloudFront.Distribution | ||
await expect(client.updateDistribution(dist)).resolves.toBe(undefined) | ||
}) | ||
it('should throw error', async () => { | ||
client = new CloudFrontUpdator({ | ||
updator: (id, conf) => { | ||
console.log(id) | ||
conf.Enabled = false | ||
return conf | ||
}, | ||
filter | ||
}, condition, { | ||
cfClient: new DummyClient() as any as AWS.CloudFront | ||
}) | ||
const dist = { | ||
Id: 'ETEST' | ||
} as AWS.CloudFront.Distribution | ||
const promise = client.updateDistribution(dist) | ||
await expect(promise).rejects.toMatch("You can not allow the action, please set 'allowSensitiveAction' option in the constructor") | ||
}) | ||
}) |
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