jeremydaly / data-api-client

A "DocumentClient" for the Amazon Aurora Serverless Data API
MIT License
443 stars 63 forks source link

Unit and Integration test cases #69

Closed kishore-perumal closed 3 years ago

kishore-perumal commented 3 years ago

Hi, Am using data-api-client for AWS lambda function in order to get the data to my UI. Now the question is how do I write my unit test cases. Here the below example code,

My lambda function consists with the below code,

/Lambda function code/ const dataApi = require("data-api-client")({ secretArn: process.env.secretArn, resourceArn: process.env.clusterArn, database: process.env.database, options: { httpOptions: { proxy: process.env.env == 'local' ? 'http://host.docker.internal:3128' : null } } }); const cognitoGroup='xyz'; const tenantStatus='Active'; exports.handler = async (event) => { const tenantDetail = await findTenantIDForCognitoUserGroup(cognitoGroup, tenantStatus); console.log('tenantDetail ':+tenantDetail ); }; function findTenantIDForCognitoUserGroup(cognitoGroup, tenantStatus) {

return dataApi.query( SELECT tenant_id, tenant_code, tenant_glue_database_name FROM tenants WHERE tenant_cognito_user_group = :cognitoGroup and deleted is NULL and tenant_status = :tenantStatus, { cognitoGroup: cognitoGroup,tenantStatus: tenantStatus }

); }

So, here my lambda function queries for data and then returns and prints. Can some one help me how can I write unit and Integration test cases for the same. I've explored and came to know using jest we can do, but am a newbie and am not sure how to write the same. Can some one guide me line by line to perform unit and interagtion test cases.

Thanks

kishore-perumal commented 3 years ago

Hi, Can you please revert me for the above problem?

ffxsam commented 3 years ago

@kishore-perumal This seems like a question better suited for a forum aimed at helping developers with general issues. Maybe try StackOverflow? I don't think anyone who maintains this repo has time to help you on the level that you're asking.

My general advice would be to somehow mock dataApi.query and just ensure that it's formatting your query the way you'd expect it to.