Category: node

Intermezzo – NestJS + Jest vs Angular + Jasmine

Bingo

Bingo is a small project, written in TypeScript , and developed with Alexandru Badita in launch break (one hour - more or less). You can find sources at https://github.com/alexandru360/PresentationBingoCards/ . Those are my blog posts for Bingo : ( scroll below for the post)

We decided to add an Angular project.  As a immediate consequence , the compile ( tsc ) of the API ( bingo-cards-api) it failes with the first error being:

../node_modules/@types/jasmine/ts3.1/index.d.ts:16:1 – error TS6200: Definitions of the following identifiers conflict with those in another file: beforeAll, beforeEach, afterAll, afterEach, describe, fdescribe, xdescribe, it, fit, xit, expect, DEFAULT_TIMEOUT_INTERVAL, CustomMatcherFactory, CustomEqualityTester

 

Obviously, we have a conflict… And the conflict is done by Angular( that comes with Jasmine by default) and Nest ( that comes with Jest) ( and us, that we have choose Jest)

 

There are 3 solving paths:

  1. Convert all to Jasmine
  2. Convert all to Jest
  3. Eliminate the tests from the Angular , eliminate the tests from Nest and create the own library to test (we have done already this, in bingo-meeting-objects-test)

 

Solution 1 : means re-factor all. Not good.

I have tried the 2 , but , in spite of many tutorials on the internet, some problems have arrived.

So we have the 3 : eliminate all references to Jest and Jasmine, with the exception of bingo-meeting-objects-test

And… it worked!

 

Bingo for meetings- Adding a CLI application–part 12

Bingo

Bingo is a small project, written in TypeScript , and developed with Alexandru Badita in launch break (one hour - more or less). You can find sources at https://github.com/alexandru360/PresentationBingoCards/ . Those are my blog posts for Bingo : ( scroll below for the post)

The easy way to test an application is to make a simple command line version . You can find the code at https://github.com/alexandru360/PresentationBingoCards/blob/master/bingo-meeting-console/index.ts

You can run also with Docker by running https://github.com/alexandru360/PresentationBingoCards/blob/master/dockerize/bingo_cli.bat

What were the steps ?

1. Install the @types/node, ts-node , typescript and others – see

https://github.com/alexandru360/PresentationBingoCards/blob/master/bingo-meeting-console/package.json

2. Create an index.ts with the required CLI ( hint: prompt, figlet, chalk , username , inquirer,console.table are good to have) – read https://dev.to/hugodias/building-your-first-interactive-node-js-cli-1g2c

3. Created an async main() and calling with

1
2
3
4
5
6
7
(async () => {
  try {
      await main();
        } catch (e) {
      console.log(JSON.stringify(e));
  }
})();

 

4. Modify package.json  to have

“main”: “dist/index.js”,

“types”: “dist/index.d.ts”,

“scripts”: {

“start”: “ts-node index.ts”,

“build”: “tsc”,

“compile”: “tsc”

}

5. Put in the root package

“scripts”: {

“test”: “cd bingo-meeting-objects-test && yarn test”,

“runConsole”: “cd bingo-meeting-console && yarn start”

}

and then run yarn runConsole

I can say that the C# console experience is better 😉

You can download the source code from https://github.com/alexandru360/PresentationBingoCards/releases/tag/CLI

Obtain data from ANAF(local IRS)

In ROmania ANAF is providing a WebAPI that allows access to some of the information that any enterprise should provide. The API is described at https://webservicesp.anaf.ro/PlatitorTvaRest/api/v3/ ,

I have made a C# console and a node,js script.

The differences:

1.it is easiear in node to make an http request.

2. For C# – I think in components. For node – I think in application.

Without further ado, here is the code

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using RestSharp;
using System;
 
namespace InfoAnafWS
{
    class Program
    {
        static void Main(string[] args)
        {
            if(args.Length == 0)
            {
                Console.WriteLine("lipseste CUI ");
                return;
            }
            var client = new RestClient("https://webservicesp.anaf.ro");
            var request = new RestRequest("PlatitorTvaRest/api/v3/ws/tva", Method.POST);
            request.RequestFormat = DataFormat.Json;
            string date = DateTime.Now.AddDays(-5).ToString("yyyy-MM-dd");
            string req = "";
            foreach (var item in args)
            {
                req += string.Format(@"{{'cui': {1}, 'data':'{0}'}}", date, item);
            }
            req = req.Replace("'", "\"");
            req = "[" + req + "]";
 
            request.AddParameter("application/json", req, ParameterType.RequestBody);
            var data = client.Execute(request);
            Console.WriteLine(data.Content);
        }
    }
}
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const start = async () => {
     
let request = require('request');
 
const d = require('delay');
await d(1000);
var fs = require('fs');
var array = fs.readFileSync('CUI.txt').toString().split("\r\n");
var start=0;
 
while(start<array.length){
    var nr = Math.floor(Math.random() * Math.floor(495))+1;
    var jsonData=[];
    console.log('start at ' + start+  ' for nr ' + nr);
    var i=0;
    while(i<nr && i+start<array.length){
        jsonData.push({"cui": array[i+start], "data":"2018-03-26"});
        i++;       
    }
     
    var finish=false;
    console.log('array :'+ jsonData[0].cui + '-'  + jsonData[nr-1].cui);
    request.post(
    { json: jsonData },
    function (error, response, body) {
        finish=true;
        if (!error && response.statusCode == 200) {
            console.log(body);
            fs.writeFile(`text${start}_${nr}.json`, JSON.stringify( body ), function (err) {
            if (err) {
                return console.log(err);
            }
 
            console.log("The file was saved!" + `text${start}_${nr}.json`);
        });
 
        }
    });
    start = start+nr;
    while(!finish){
        console.log('waiting');
        await d(13000);
    }
     
 
}
console.log('finish')
return;
 
}
start();

Andrei Ignat weekly software news(mostly .NET)

* indicates required

Please select all the ways you would like to hear from me:

You can unsubscribe at any time by clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.