# data_completeness_updater lambda
Lambda to populate the data_completeness table in Delphi API DB.
It queries SLZ database(apps_etl_unit_of_work and apps_etl_dabricks_execution tables) 
for completeness status and transfer statuses to Delphi API DB.

## Lambda Environment variables
To execute the Apps Manager Lambda the following environment variables must be configured:

| Variable                    | Description                                      
|-----------------------------|--------------------------------------------------
| `ENVIRONMENT`               | Environment name (`prod`, `dev`)                 
| `RDS_SECRETS_KEY`           | credentials to slz database                      
| `API_DB_SECRETS_KEY`        | credentials to delphi API database               
| `BATCH_SIZE`                | how many records from SLZ DB process during 1 lambda run
                              

## Lambda Input
No required params for lambda. Run with empty payload

## Lambda Output
In case of successful lambda execution the following output will be provided:
```json
{
    "meta": {
        "status": "OK"
    }
}
```

If any kind of exception occurred, execution will fail
(in order to see failures on monitoring tab in AWS console) and error will be logged

## Running tests
There are two type of tests: integration(which requires test database) and not integration

#### Integration
Starting tests with a local environment.
It requires a test database to be created and migrations to be applied. To set up test 
database docker-compose could be used
```shell script
docker-compose up -d pg migration
export DB_URL=postgresql+psycopg2://localhost/slz_test 
make test_integr
```

Another way is running tests within docker containers. First and foremost it's required to perform
login to the AWS console to be able to pull images.
```shell script
make docker/login
```

With a following command it will set up a database container, update it with migrations and start tests.
```shell script
make docker/integration
```
This command starts container with PostgreSQL database, applies migrations to it and invokes
tests. After everything is done temporary containers are removed automatically.

#### Not integration
Starting tests with a local environment.
```shell script
make test
```
Running tests within docker container
```shell script
make docker/login
make docker/test
```
