Skip to content

Commit

Permalink
fix: fix var naming, add some test
Browse files Browse the repository at this point in the history
  • Loading branch information
T1B0 committed Jan 19, 2024
1 parent 35af9b5 commit 516e2e8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/tcp.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ export const sendCommandWithResponse = (s: Socket) =>
(command: number, payload: Buffer): Promise<CommandResponse> => {

const payloadSize = payload.length + COMMAND_LENGTH;
let buffer = Buffer.alloc(8);
const head = Buffer.alloc(8);

buffer.writeUint32LE(payloadSize, 0);
buffer.writeUint32LE(command, 4);
head.writeUint32LE(payloadSize, 0);
head.writeUint32LE(command, 4);

console.log(
'==> CMD', buffer.readInt32LE(4),
'==> CMD', head.readInt32LE(4),
translateCommandCode(command),
'LENGTH', buffer.readInt32LE(0));
'LENGTH', head.readInt32LE(0));

const cmd = Buffer.concat([buffer, payload]);
const cmd = Buffer.concat([head, payload]);
console.log('==> sending cmd', command, cmd /**, cmd.toString()*/);
console.log('==> socket write', s.write(cmd));

Expand Down
39 changes: 39 additions & 0 deletions src/wire/token/delete-token.command.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { DELETE_TOKEN } from './delete-token.command.js';

describe('DeleteToken', () => {

describe('serialize', () => {

const name = 'test-token';

it('serialize 1 name into buffer', () => {

assert.deepEqual(
DELETE_TOKEN.serialize(name).length,
1 + name.length
);
});

it('throw on name < 1', () => {
assert.throws(
() => DELETE_TOKEN.serialize('')
);
});

it("throw on name > 255 bytes", () => {
assert.throws(
() => DELETE_TOKEN.serialize("YoLo".repeat(65))
);
});

it("throw on name > 255 bytes - utf8 version", () => {
assert.throws(
() => DELETE_TOKEN.serialize("¥Ø£Ø".repeat(33))
);
});

});
});

0 comments on commit 516e2e8

Please sign in to comment.