Skip to content

Commit

Permalink
rename deviceToken to apiKey
Browse files Browse the repository at this point in the history
  • Loading branch information
nicky-ru committed Jul 26, 2023
1 parent 99762f8 commit fc05c72
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
And provide DEVICE_TOKEN and HTTP_ROUTE that can be found in W3bstream project.

```ts
const api_key = "API_KEY";
const apiKey = "API_KEY";
const httpRoute = "HTTP_ROUTE";
```

Expand Down Expand Up @@ -65,7 +65,7 @@ const dataGenerator = new DataPointGenerator<TemperatureDataPoint>(
Create a new instance of the `Simulator` class, initialize it and set a `DataPointGenerator` that you created earlier:

```ts
const simulator = new Simulator(deviceToken, httpRoute);
const simulator = new Simulator(apiKey, httpRoute);
simulator.init();
simulator.dataPointGenerator = dataGenerator;
```
Expand Down
4 changes: 2 additions & 2 deletions src/Simulator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export class Simulator {

public publicKey: string = "";

constructor(deviceToken: string, httpRoute: string) {
this._client = new W3bstreamClient(httpRoute, deviceToken);
constructor(apiKey: string, httpRoute: string) {
this._client = new W3bstreamClient(httpRoute, apiKey);
}

init(pathToPrivateKey?: string) {
Expand Down
17 changes: 8 additions & 9 deletions src/Simulator/simulator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ jest.mock("w3bstream-client-js", () => {
};
});

const PUB_TOKEN_1 = "pub_token_1";
const PUB_TOKEN_2 = "pub_token_2";
const API_KEY = "api_key";
const W3BSTREAM_ENDPOINT = "http://localhost:3000";

describe("simulator", () => {
Expand All @@ -37,7 +36,7 @@ describe("simulator", () => {
let publicKey2: string;

beforeEach(() => {
simulator1 = new Simulator(PUB_TOKEN_1, W3BSTREAM_ENDPOINT);
simulator1 = new Simulator(API_KEY, W3BSTREAM_ENDPOINT);
simulator1.init();
publicKey1 = simulator1.publicKey;
});
Expand All @@ -51,7 +50,7 @@ describe("simulator", () => {
const newPath = "./testing-simulator1/new-path";
movePkFile("./", newPath);

simulator2 = new Simulator(PUB_TOKEN_2, W3BSTREAM_ENDPOINT);
simulator2 = new Simulator(API_KEY, W3BSTREAM_ENDPOINT);
simulator2.init(newPath);

publicKey2 = simulator2.publicKey;
Expand All @@ -64,7 +63,7 @@ describe("simulator", () => {
expect(publicKey1.length).toEqual(130);
});
it("should create new id if path to file is wrong", () => {
simulator2 = new Simulator(PUB_TOKEN_2, W3BSTREAM_ENDPOINT);
simulator2 = new Simulator(API_KEY, W3BSTREAM_ENDPOINT);
simulator2.init("./wrong-path");
publicKey2 = simulator2.publicKey;

Expand All @@ -77,7 +76,7 @@ describe("simulator", () => {
expect(privateKey.length).toEqual(64);
});
it("should reuse private.key file if one is provided", () => {
simulator2 = new Simulator(PUB_TOKEN_2, W3BSTREAM_ENDPOINT);
simulator2 = new Simulator(API_KEY, W3BSTREAM_ENDPOINT);
simulator2.init();

expect(publicKey1).toEqual(simulator2.publicKey);
Expand All @@ -93,7 +92,7 @@ describe("simulator", () => {
let message1: W3bStreamMessage;

beforeEach(() => {
simulator1 = new Simulator(PUB_TOKEN_1, W3BSTREAM_ENDPOINT);
simulator1 = new Simulator(API_KEY, W3BSTREAM_ENDPOINT);
simulator1.init();

dataGenerator = new DataPointGenerator<TemperatureDataPoint>(() => ({
Expand Down Expand Up @@ -130,7 +129,7 @@ describe("simulator", () => {
expect(message1.signature.length).toBeGreaterThan(0);
});
it("should throw if no data generator is set", () => {
const simulator2 = new Simulator(PUB_TOKEN_2, W3BSTREAM_ENDPOINT);
const simulator2 = new Simulator(API_KEY, W3BSTREAM_ENDPOINT);
simulator2.init();
expect(() => simulator2.generateSingleMessage()).toThrow(
NoDataPointGeneratorError
Expand All @@ -148,7 +147,7 @@ describe("simulator", () => {
let mockSendMsg: jest.SpyInstance;

beforeEach(() => {
simulator1 = new Simulator(PUB_TOKEN_1, W3BSTREAM_ENDPOINT);
simulator1 = new Simulator(API_KEY, W3BSTREAM_ENDPOINT);
simulator1.init();

dataGenerator = new DataPointGenerator<TemperatureDataPoint>(() => ({
Expand Down

0 comments on commit fc05c72

Please sign in to comment.