dependabot[bot] on npm_and_yarn
Bump copy-props from 2.0.4 to 2… (compare)
dependabot[bot] on npm_and_yarn
dependabot[bot] on npm_and_yarn
Bump codecov from 3.6.5 to 3.8.… (compare)
dependabot[bot] on npm_and_yarn
Bump pathval from 1.1.0 to 1.1.… (compare)
dependabot[bot] on npm_and_yarn
dependabot[bot] on npm_and_yarn
Bump node-fetch from 2.6.0 to 2… (compare)
Makes sense. I ended up just mocking the persistence layer with a fake persistence adapter.
I have a dedicated persistence.js
module with a method getPersistenceAdapter
. That initializes my S3PersistenceAdapter with a bucket name (and any other settings) and is called during the custom skill initialization.
In test I use sinon
to stub out that method.
stubPersistenceAdapter(sinon.stub(persistence, 'getPersistenceAdapter'));
I then pass that into the method below to get a standard mock for the persistence adapter
/**
* Creates a consistent stub for the persistence adapter which saves/loads attributes
* @param stub - a sinon stub which has stubbed the getPersistenceAdapter
* @returns a sinon stub which has been setup as a persistence adapter
*/
export const stubPersistenceAdapter = (stub) => {
let savedAttributes = null;
stub.returns({
getAttributes: (requestEnvelope) => { return Promise.resolve(savedAttributes);},
saveAttributes: (requestEnvelope, attributes) => {
savedAttributes = attributes;
return Promise.resolve();
}
});
stub.getSavedAttributes = () => savedAttributes;
stub.setSavedAttributes = (val) => savedAttributes = val;
return stub;
};
The nice thing about this solution is that it works regardless of the persistence layer (S3, Dymamo, custom?). It also allows me to get/set the attributes that have been written so that I can examine them directly in my tests. Most of my unit tests look at the responseBuilder generated output from the handler as well as the data written to persistence. In all cases I can easily populate that data before the test runs.
Anyway, that's what's worked for me so far :)
virtualAlexa.dynamoDB().mock();
Hi @davinci26 , with virtual-alexa , this is the documentation for dynamo
https://github.com/bespoken/virtual-alexa/blob/master/docs/Externals.md#dynamodb
In order to put some items, use the dynamo put method, and then you can use the get