Skip to content

Commit

Permalink
Raise error when bsnl jwt referesh fails (#5276)
Browse files Browse the repository at this point in the history
Related story card:
[sc-11112](https://app.shortcut.com/simpledotorg/story/11112/p1-bsnl-smses-failing-with-401)

The task to refresh bsnl token would fail silently when we were
arbitrarily blacklisted. We want to an add alert to catch these issues
with the api earlier on.
  • Loading branch information
qptr authored Sep 14, 2023
1 parent 431602f commit b9da412
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/tasks/scripts/refresh_bsnl_sms_jwt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def call
jwt = response.body.delete_prefix('"').delete_suffix('"')
config = Configuration.find_or_create_by(name: "bsnl_sms_jwt")
config.update!(value: jwt)
else
response.error!
end
end
end
8 changes: 8 additions & 0 deletions spec/lib/tasks/scripts/refresh_bsnl_sms_jwt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
expect(request).to have_been_made
expect(Configuration.fetch("bsnl_sms_jwt")).to eq("new_jwt")
end

it "raises an error if the HTTP call fails" do
stub_request(:post, "https://bulksms.bsnl.in:5010/api/Create_New_API_Token").to_return(status: 401)
expect { described_class.new("1", "invalid username", "invalid password", "X").call }.to raise_error

stub_request(:post, "https://bulksms.bsnl.in:5010/api/Create_New_API_Token").to_return(status: 500)
expect { described_class.new("1", "username", "password", "X").call }.to raise_error
end
end
end
end

0 comments on commit b9da412

Please sign in to comment.