Skip to content

Commit

Permalink
feat: return probe info after send code to the probe
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Nov 2, 2023
1 parent c2d1c3f commit b00668c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/adoption-code/route/adoption-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ import { codeSender } from '../sender.js';

const handle = async (ctx: Context): Promise<void> => {
const request = ctx.request.body as AdoptionCodeRequest;
const result = await codeSender.sendCode(request);
const socket = await codeSender.sendCode(request);

ctx.body = {
result,
uuid: socket.data.probe.uuid,
version: socket.data.probe.version,
status: socket.data.probe.status,
city: socket.data.probe.location.city,
country: socket.data.probe.location.country,
latitude: socket.data.probe.location.latitude,
longitude: socket.data.probe.location.longitude,
asn: socket.data.probe.location.asn,
network: socket.data.probe.location.network,
};
};

Expand Down
4 changes: 2 additions & 2 deletions src/adoption-code/sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { AdoptionCodeRequest } from './types.js';
export class CodeSender {
constructor (private readonly fetchWsSockets: typeof fetchSockets) {}

async sendCode (request: AdoptionCodeRequest): Promise<string> {
async sendCode (request: AdoptionCodeRequest): Promise<RemoteProbeSocket> {
const socket = await this.findSocketByIp(request.ip);

if (!socket) {
Expand All @@ -16,7 +16,7 @@ export class CodeSender {

this.sendToSocket(socket, request.code);

return 'Code was sent to the probe.';
return socket;
}

private async findSocketByIp (ip: string) {
Expand Down
10 changes: 9 additions & 1 deletion test/tests/integration/adoption-code/adoption-code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@ describe('Adoption code', () => {
})
.expect(200).expect((response) => {
expect(response.body).to.deep.equal({
result: 'Code was sent to the probe.',
uuid: '1-1-1-1-1',
version: '0.14.0',
status: 'initializing',
city: 'Dallas',
country: 'US',
latitude: 32.7831,
longitude: -96.8067,
asn: 20004,
network: 'The Constant Company LLC',
});
});

Expand Down

0 comments on commit b00668c

Please sign in to comment.