Skip to content

Commit

Permalink
TEST: fail if no auth
Browse files Browse the repository at this point in the history
  • Loading branch information
slivingston committed Feb 15, 2025
1 parent 4b91b03 commit 1d98219
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
export function instanceKeepAlive(instanceId: string, token: string) {
fetch(`https://api.rerobots.net/instance/${instanceId}/ka`, {
return fetch(`https://api.rerobots.net/instance/${instanceId}/ka`, {
method: 'POST',
headers: {
Authorization: 'Bearer ' + token,
'Content-Type': 'application/json',
},
})
.then((res) => {
if (res.ok) {
setTimeout(() => {
instanceKeepAlive(instanceId, token);
}, 45000);
return;
}
})
.catch((err) => {
console.log(err);
});
}).then((res) => {
if (res.ok) {
setTimeout(() => {
instanceKeepAlive(instanceId, token);
}, 45000);
return;
} else if (res.status < 404) {
throw new Error(`${res.status}`);
}
});
}
7 changes: 7 additions & 0 deletions tests/instanceKeepAlive.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { instanceKeepAlive } from '../src/util';

test('unauthenticated calls fail', () => {
return expect(
instanceKeepAlive('1926b858-0d00-4b84-b7ca-5c56be880525', ''),
).rejects.toThrow();
});

0 comments on commit 1d98219

Please # to comment.