Skip to content

Commit

Permalink
tests refined
Browse files Browse the repository at this point in the history
  • Loading branch information
avsol committed Dec 27, 2018
1 parent 1f2029d commit be27290
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 69 deletions.
File renamed without changes.
33 changes: 0 additions & 33 deletions spec/test.spec.ts

This file was deleted.

39 changes: 39 additions & 0 deletions spec/tests.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/// <reference path="../SupercondActorTypes.d.ts" />

// When running in the Service Fabric Business Platform
// the global _SupercondActor instance will be provided by the environment.
// For testing we need a mock.
import { _SupercondActorMock } from "./support/SupercondActorMock";
(global as any)._SupercondActor = new _SupercondActorMock();

// entry points class definition from the index.ts file
import { MyEntryPointsDefinition } from "../src/index";

// Here is our source code for entry points
require('../src/index.ts');

// Instead of testing source code we can test the final bundle
// to make sure we have everything we need in it
// (comment the require statement above and uncomment below,
// run 'npm run build' then 'npm test'):
// require('../dist/Scripts/bundle.js')

describe("_SupercondActor object", () => {
it("should save and increment counter", async () => {
let entry: MyEntryPointsDefinition = (global as any).MyEntryPoints;

let nbr = 7;
let res = await entry.setCounter(nbr);
expect(res).toBe(nbr);

res = await entry.incrementCounter();
expect(res).toBe(8);

res = await entry.incrementCounter();
expect(res).toBe(9);

let keys = await entry.listStateKeys();
expect(keys.length).toBe(1);
expect(keys[0]).toBe('counter');
});
});
3 changes: 2 additions & 1 deletion src/appConfig/ScheduledServices/MyService.config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"ServiceName": "My State Service",
"GroupName": "Demo Services",
"MetadataJson": "{\"Description\": \"My state service\"}",
"MetadataJson": "{\"Description\": \"My state scheduled service\"}",
"Job": {
"StopRequested": true,
"JobSchedule": {
"IntervalSeconds": 5
}
Expand Down
2 changes: 1 addition & 1 deletion src/appConfig/ScheduledServices/MyService.job.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// calling one of my global entry points defined in the index.ts file
let counter = await MyEntryPoints.IncrementCounter();
let counter = await MyEntryPoints.incrementCounter();
console.log('Message from my service: counter=', counter);
38 changes: 4 additions & 34 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// you should be able to call your entry point from your service's job script at runtime.

export class MyEntryPointsDefinition {
SetCounter = async function (nbr: number): Promise<any> {
setCounter = async function (nbr: number): Promise<any> {
// save number to local state
let res = await _SupercondActor.Context.saveLocalStateAsync('counter', nbr);
_SupercondActor.Logger.logInfo(['saveLocalStateAsync result', res]);
Expand All @@ -17,7 +17,7 @@ export class MyEntryPointsDefinition {
return counter;
};

IncrementCounter = async function (): Promise<any> {
incrementCounter = async function (): Promise<any> {
// read counter from local state
let counter = await _SupercondActor.Context.getLocalStateAsync('counter');
_SupercondActor.Logger.logInfo(['getLocalStateAsync counter', counter]);
Expand All @@ -34,41 +34,11 @@ export class MyEntryPointsDefinition {
return res;
};

ListStateKeys = async function (): Promise<string[]> {
listStateKeys = async function (): Promise<string[]> {
let res = await _SupercondActor.Context.getLocalStateKeysAsync();
_SupercondActor.Logger.logInfo(['getLocalStateKeysAsync', res]);
return res;
};
}

(global as any).MyEntryPoints = new MyEntryPointsDefinition();


// (global as any).SetCounter = async function (nbr: number) {
// // save number to local state
// let res = await _SupercondActor.Context.saveLocalStateAsync('counter', nbr);
// _SupercondActor.Logger.logInfo(['saveLocalStateAsync result', res]);

// // read number from local state
// let counter = await _SupercondActor.Context.getLocalStateAsync('counter');
// _SupercondActor.Logger.logInfo(['getLocalStateAsync result', counter]);

// return counter;
// };

// (global as any).IncrementCounter = async function () {
// // read counter from local state
// let counter = await _SupercondActor.Context.getLocalStateAsync('counter');
// _SupercondActor.Logger.logInfo(['getLocalStateAsync counter', counter]);

// // increment counter
// if (!counter) {
// counter = 0;
// }
// counter++;

// // save counter to local state
// let res = await _SupercondActor.Context.saveLocalStateAsync('counter', counter);
// _SupercondActor.Logger.logInfo(['saveLocalStateAsync counter', res]);
// return res;
// }
(global as any).MyEntryPoints = new MyEntryPointsDefinition();

0 comments on commit be27290

Please sign in to comment.