I have simple Jest case where I need to create the table at the beginning, populate it and then run some tests. After all tests are finished, I need to delete the table in DynamoDB.
I tried with beforeAll, creating the table, then testing, and then with afterAll deleting the table. Nevertheless, it runs non-deterministically, so the population tries to run before creating the table, or the table tries to be deleted before ever creating it.
My code
beforeAll(() => {
await createTable();
populateTable();
//setupLDAPConnection();
});
afterAll(() => {
deleteTable();
});
describe('The program gets list of AD groups', function () {
it('should get a list of user groups in the Active Directory', async () => {
//const result = await userSyncFunction.handler(undefined);
//expect(result).to.be.an('object');
//console.log('2');
});
});
populateTable = () => {
agents.forEach((agent) => {
docClient.put(agent, (err, data) => {
if (err) {
console.log("Error", err);
} else {
console.log("Agent inserted", data);
}
});
});
};
createTable = async () => {
dynamoDb.createTable(agent_table, (err, data) => {
if (err) {
console.log("Error", err);
} else {
console.log("Table created");
}
});
};
deleteTable = () => {
dynamoDb.deleteTable( { TableName: 'AGENT_LIST' }, function(err, data) {
if (err)
console.log(err, err.stack);
else {
console.log('Table deleted');
}
});
};
Any ideas?
Thank you.