Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enedis : Use defaut activation date in case getContract fails #161

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading