Skip to content

Commit

Permalink
Enedis : Use defaut activation date in case getContract fails (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles authored Jun 5, 2024
1 parent 74945ed commit 874f726
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion core/enedis/enedis.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,15 @@ module.exports = function EnedisModel(logger, db, redisClient) {
logger.info(`Enedis: Found ${usagePointIds.length} usage points for user ${job.userId}`);
// Foreach usage points, we generate one job per request to make
await Promise.each(usagePointIds, async (usagePointId) => {
const contract = await getContract(account.id, usagePointId);
let contract;
try {
contract = await getContract(account.id, usagePointId);
} catch (e) {
logger.warn(
`Failed to get contract for usage_point ${usagePointId}. Will continue with a default value for last activation date.`,
);
}

let oldestDate = job.start ? dayjs(job.start) : dayjs().subtract(2, 'years');

// We cannot get data before lastActivationDate
Expand Down
4 changes: 2 additions & 2 deletions test/core/enedis/enedis.dailyRefreshAllUsers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('EnedisWorker.dailyRefreshAllUsers', function Describe() {
({ enedisModel, shutdown } = await initEnedisListener());
await shutdown();
});
it('should publish 2 jobs', async () => {
it('should publish 4 jobs', async () => {
// Insert broken enedis user data
await TEST_DATABASE_INSTANCE.t_account.insert({
id: 'ab9c205a-d090-4c97-84b5-d2a9eb932201',
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('EnedisWorker.dailyRefreshAllUsers', function Describe() {
mockAccessTokenRefresh();
await enedisModel.dailyRefreshOfAllUsers();
const counts = await enedisModel.queue.getJobCounts('wait', 'completed', 'failed');
expect(counts).to.deep.equal({ wait: 2, completed: 0, failed: 0 });
expect(counts).to.deep.equal({ wait: 4, completed: 0, failed: 0 });
});
it('should play job', async () => {
// First, finalize Enedis Oauth process
Expand Down

0 comments on commit 874f726

Please sign in to comment.