/** * Clear test data */ async function clearData () { // remove challenge in Elasticsearch await esClient.delete({ index: config.ES.ES_INDEX, type: config.ES.ES_TYPE, id: challenge.id, refresh: 'true' // refresh ES so that it is effective for read operations instantly }) // remove completedChallenge in Elasticsearch await esClient.delete({ index: config.ES.ES_INDEX, type: config.ES.ES_TYPE, id: completedChallenge.id, refresh: 'true' // refresh ES so that it is effective for read operations instantly }) await challenge.delete() await completedChallenge.delete() await timelineTemplate.delete() await phase.delete() await phase2.delete() await challengeType.delete() }
const initES = async () => { if (process.argv.length === 3 && process.argv[2] === 'force') { logger.info(`Delete index ${config.ES.ES_INDEX} if any.`) try { await client.indices.delete({ index: config.ES.ES_INDEX }) } catch (err) { // ignore } } const exists = await client.indices.exists({ index: config.ES.ES_INDEX }) if (exists) { logger.info(`The index ${config.ES.ES_INDEX} exists.`) } else { logger.info(`The index ${config.ES.ES_INDEX} will be created.`) const body = { mappings: {} } body.mappings[config.get('ES.ES_TYPE')] = { properties: { id: { type: 'keyword' } } } await client.indices.create({ index: config.ES.ES_INDEX, body }) } }
index: config.ES.ES_INDEX, type: config.ES.ES_TYPE, id: challenge.id, body: _.assignIn({ numOfSubmissions: 0, numOfRegistrants: 0 }, challenge.originalItem()), index: config.ES.ES_INDEX, type: config.ES.ES_TYPE, id: completedChallenge.id, body: _.assignIn({ numOfSubmissions: 0, numOfRegistrants: 0 }, completedChallenge.originalItem()),