Got my app ported from elixir to serverless finall...
# sst
t
Got my app ported from elixir to serverless finally. Next step is refactoring postgres for dynamo. Realizing I'm not sure how to run my jest tests anymore since they need dynamo access. How are people doing this?
A very simple example is I have a domain that handles generating random tokens with some associated data, saving them to dynamo db, then retrieving them later
f
Were ur jest tests running against a local postgres?
g
jest mock the dynamodb client, something like this:
Copy code
const mockDynamoDBError = jest.fn();
const mockDynamoDBData = jest.fn();
jest.mock('aws-sdk/clients/dynamodb', () => {
  return class DynamoDB {
    getItem(_params, callback) {
      callback(mockDynamoDBError(), mockDynamoDBData())
    }

    putItem(_params, callback) {
      callback(mockDynamoDBError(), mockDynamoDBData())
    }

    deleteItem(_params, callback) {
      callback(mockDynamoDBError(), mockDynamoDBData())
    }
  }
})
a
Why did you ported from elixir? isn’t that language trending right now?
I mean why was made on it on the first place..?
o
I use dynamo db local
Also some code uses other aws services (like an sqs queue) so for those tests I just set up a sqs queue to act as a sink for any code running locally, gets passed in as a env variable
t
@Frank Yeah previously running against a local postgres @Adrián Mouly I got into elixir like 5 years ago and it was the default way I was building things and using my own framework I had developed. Saw the light with serverless and was ready to move on. It's a side project so using it to learn Got it so looks like people are either mocking it or using dynamodb local. Wonder if in the serverless world there will be a new pattern of running your tests in a lambda with access to all the real infra
Totally forgot that my user can access dynamo (and all other resources) from my machine since there's no vpc's involved. Was able to run the test against the dynamo table deployed by the cdk stack
ez
o
Yup - I do that for other resources, running dynamo locally just reduces the latency to make tests run faster
t
lol I had another question about an empty
sk
with dynamo-toolbox and I found your answer in a github issue
p
"Saw the light with serverless and was ready to move on." Big agreement with that. 🎉