From 4eed0ca00429591c4ee0633248b3bb9b2f34c67d Mon Sep 17 00:00:00 2001 From: yoshiaki-yamada Date: Wed, 4 Jan 2023 11:53:19 +0900 Subject: [PATCH] feat: Implement dummy PersistenceAdapter for TestInput --- src/utils/testSupport/TestingUtils.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/utils/testSupport/TestingUtils.ts b/src/utils/testSupport/TestingUtils.ts index c42dff0..5bcffda 100644 --- a/src/utils/testSupport/TestingUtils.ts +++ b/src/utils/testSupport/TestingUtils.ts @@ -18,6 +18,7 @@ import { ResponseBuilder, ResponseFactory, Skill, + PersistenceAdapter, } from 'ask-sdk-core'; import { Intent, @@ -420,6 +421,26 @@ function dummyRequestEnvelope(request?: Request): RequestEnvelope { }; } +class DummyPersistenceAdapter implements PersistenceAdapter { + private attributes: { [key: string]: any } | undefined = {}; + + async getAttributes(_: RequestEnvelope) { + if (this.attributes) { + return this.attributes; + } else { + return {}; + } + } + + async saveAttributes(_: RequestEnvelope, attributes: { [key: string]: any }) { + this.attributes = attributes; + } + + async deleteAttributes(_: RequestEnvelope) { + this.attributes = undefined; + } +} + function dummyControlInput(request?: Request): ControlInput { const handlerInput = { requestEnvelope: dummyRequestEnvelope(request), @@ -440,5 +461,6 @@ function dummyControlInput(request?: Request): ControlInput { } const dummyAttributesManager: AttributesManager = AttributesManagerFactory.init({ requestEnvelope: dummyRequestEnvelope(), + persistenceAdapter: new DummyPersistenceAdapter(), }); const dummyResponseBuilder: ResponseBuilder = ResponseFactory.init();