Skip to content

Commit

Permalink
fix(script): update scripts for latest packages versions
Browse files Browse the repository at this point in the history
  • Loading branch information
akanass committed Feb 1, 2021
1 parent 313b854 commit 3f20358
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 47 deletions.
1 change: 0 additions & 1 deletion nest-cli.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"language": "ts",
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
9 changes: 3 additions & 6 deletions test/integration/aes.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ describe('- Integration aes.service.test.ts file', () => {
*/
test('- `AesService.createKey()` function must return an Observable with error if AesService key parameters are wrong', (done) => {
aesService.createKey(null, null).subscribe(() => null, err => {
expect(err.message).toBe('The "password" argument must be one of type string, ' +
'Buffer, TypedArray, or DataView. Received type object');
expect(err.message).toBe('The "password" argument must be of type string or an instance of ArrayBuffer, Buffer, TypedArray, or DataView. Received null');
done();
});
});
Expand Down Expand Up @@ -122,8 +121,7 @@ describe('- Integration aes.service.test.ts file', () => {
encryptWithAesKey(Buffer.from('data'))
)
.subscribe(() => null, err => {
expect(err.message).toBe('The first argument must be one of type string, ' +
'Buffer, ArrayBuffer, Array, or Array-like Object. Received type object');
expect(err.message).toBe('The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received null');
done();
});
});
Expand All @@ -138,8 +136,7 @@ describe('- Integration aes.service.test.ts file', () => {
decryptWithAesKey(Buffer.from('a3d4bb8fcb8ec0e24a86cef07a28e3af', 'hex'))
)
.subscribe(() => null, err => {
expect(err.message).toBe('The first argument must be one of type string, ' +
'Buffer, ArrayBuffer, Array, or Array-like Object. Received type object');
expect(err.message).toBe('The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received null');
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/integration/hash.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('- Integration hash.service.test.ts file', () => {
test('- `HashService.generate()` function must return an Observable with error if parameters are wrong', (done) => {
hashService.generate(undefined, undefined, undefined, undefined, undefined)
.subscribe(() => null, err => {
expect(err.message).toBe('The "digest" argument must be one of type string or null. Received type undefined');
expect(err.message).toBe('The "digest" argument must be of type string. Received undefined');
done();
}
);
Expand Down
28 changes: 14 additions & 14 deletions test/integration/pem.service.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { flatMap } from 'rxjs/operators';
import { mergeMap } from 'rxjs/operators';
import {
CertificateCreationResult,
CertificateSubjectReadResult,
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('- Integration pem.service.test.ts file', () => {
'`{country, state, locality, organization, organizationUnit, commonName, emailAddress}`', (done) => {
pemService.createCertificate()
.pipe(
flatMap((c: CertificateCreationResult) => pemService.readCertificateInfo(c.certificate))
mergeMap((c: CertificateCreationResult) => pemService.readCertificateInfo(c.certificate))
)
.subscribe((certificateSubjectReadResult: CertificateSubjectReadResult) => {
expect(certificateSubjectReadResult).toHaveProperty('country');
Expand All @@ -121,7 +121,7 @@ describe('- Integration pem.service.test.ts file', () => {
test('- `PemService.getPublicKey()` Observable must return a `PublicKeyCreationResult` object `{publicKey}`', (done) => {
pemService.createPrivateKey()
.pipe(
flatMap((c: PrivateKeyCreationResult) => pemService.getPublicKey(c.key))
mergeMap((c: PrivateKeyCreationResult) => pemService.getPublicKey(c.key))
)
.subscribe((publicKeyCreationResult: PublicKeyCreationResult) => {
expect(publicKeyCreationResult).toHaveProperty('publicKey');
Expand All @@ -147,7 +147,7 @@ describe('- Integration pem.service.test.ts file', () => {
test('- `PemService.getFingerprint()` Observable must return a `FingerprintResult` object `{fingerprint}`', (done) => {
pemService.createCertificate()
.pipe(
flatMap((c: CertificateCreationResult) => pemService.getFingerprint(c.certificate))
mergeMap((c: CertificateCreationResult) => pemService.getFingerprint(c.certificate))
)
.subscribe((fingerprintResult: FingerprintResult) => {
expect(fingerprintResult).toHaveProperty('fingerprint');
Expand All @@ -161,7 +161,7 @@ describe('- Integration pem.service.test.ts file', () => {
test('- `PemService.getModulus()` Observable must return a `ModulusResult` object `{modulus}`', (done) => {
pemService.createCertificate()
.pipe(
flatMap((c: CertificateCreationResult) => pemService.getModulus(c.certificate))
mergeMap((c: CertificateCreationResult) => pemService.getModulus(c.certificate))
)
.subscribe((modulusResult: ModulusResult) => {
expect(modulusResult).toHaveProperty('modulus');
Expand All @@ -175,7 +175,7 @@ describe('- Integration pem.service.test.ts file', () => {
test('- `PemService.getDhparamInfo()` Observable must return a `DhParamInfoResult` object `{size, prime}`', (done) => {
pemService.createDhparam()
.pipe(
flatMap((dh: DhParamKeyCreationResult) => pemService.getDhparamInfo(dh.dhparam))
mergeMap((dh: DhParamKeyCreationResult) => pemService.getDhparamInfo(dh.dhparam))
)
.subscribe((dhParamInfoResult: DhParamInfoResult) => {
expect(dhParamInfoResult).toHaveProperty('size');
Expand All @@ -190,13 +190,13 @@ describe('- Integration pem.service.test.ts file', () => {
test('- `PemService.createPkcs12()` Observable must return a `PKCS12CreationResult` object `{pkcs12}`', (done) => {
pemService.createPrivateKey()
.pipe(
flatMap((pk: PrivateKeyCreationResult) =>
mergeMap((pk: PrivateKeyCreationResult) =>
pemService.createCertificate({
clientKey: pk.key,
selfSigned: true
})
),
flatMap((c: CertificateCreationResult) => pemService.createPkcs12(c.clientKey, c.certificate, 'password'))
mergeMap((c: CertificateCreationResult) => pemService.createPkcs12(c.clientKey, c.certificate, 'password'))
)
.subscribe((pkcs12Result: PKCS12CreationResult) => {
expect(pkcs12Result).toHaveProperty('pkcs12');
Expand All @@ -220,14 +220,14 @@ describe('- Integration pem.service.test.ts file', () => {
test('- `PemService.createPkcs12()` Observable must return true', (done) => {
pemService.createPrivateKey()
.pipe(
flatMap((pk: PrivateKeyCreationResult) =>
mergeMap((pk: PrivateKeyCreationResult) =>
pemService.createCertificate({
clientKey: pk.key,
selfSigned: true
})
),
flatMap((c: CertificateCreationResult) => pemService.createPkcs12(c.clientKey, c.certificate, 'password')),
flatMap((pkcs12Result: PKCS12CreationResult) => pemService.checkPkcs12(pkcs12Result.pkcs12, 'password'))
mergeMap((c: CertificateCreationResult) => pemService.createPkcs12(c.clientKey, c.certificate, 'password')),
mergeMap((pkcs12Result: PKCS12CreationResult) => pemService.checkPkcs12(pkcs12Result.pkcs12, 'password'))
)
.subscribe((isValid: boolean) => {
expect(isValid).toBeTruthy();
Expand All @@ -241,12 +241,12 @@ describe('- Integration pem.service.test.ts file', () => {
test('- `PemService.verifySigningChain()` Observable must return true', (done) => {
pemService.createCertificate({ commonName: 'CA Certificate' })
.pipe(
flatMap((ca: CertificateCreationResult) =>
mergeMap((ca: CertificateCreationResult) =>
pemService.createCertificate({
serviceKey: ca.serviceKey, serviceCertificate: ca.certificate, serial: Date.now()
})
.pipe(
flatMap((cert: CertificateCreationResult) =>
mergeMap((cert: CertificateCreationResult) =>
pemService.verifySigningChain(cert.certificate, ca.certificate)
)
)
Expand All @@ -264,7 +264,7 @@ describe('- Integration pem.service.test.ts file', () => {
test('- `PemService.checkCertificate()` Observable must return true', (done) => {
pemService.createCertificate()
.pipe(
flatMap((c: CertificateCreationResult) => pemService.checkCertificate(c.certificate))
mergeMap((c: CertificateCreationResult) => pemService.checkCertificate(c.certificate))
)
.subscribe((isValid: boolean) => {
expect(isValid).toBeTruthy();
Expand Down
18 changes: 9 additions & 9 deletions test/integration/rsa.service.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Buffer } from 'buffer';
import { Observable, of } from 'rxjs';
import { flatMap } from 'rxjs/operators';
import { mergeMap } from 'rxjs/operators';
import { NodeRSA, RsaService } from '../../src';
import {
decryptPrivate,
Expand Down Expand Up @@ -375,11 +375,11 @@ describe('- Unit rsa.service.test.ts file', () => {
rsaService.loadKey(testKey)
)
.pipe(
flatMap((key: Observable<NodeRSA>) =>
mergeMap((key: Observable<NodeRSA>) =>
key
.pipe(
encryptPrivate('data'),
flatMap((enc: Buffer) =>
mergeMap((enc: Buffer) =>
key
.pipe(
decryptPublic(enc)
Expand Down Expand Up @@ -416,11 +416,11 @@ describe('- Unit rsa.service.test.ts file', () => {
rsaService.loadKey(testKey)
)
.pipe(
flatMap((key: Observable<NodeRSA>) =>
mergeMap((key: Observable<NodeRSA>) =>
key
.pipe(
encryptPublic('data'),
flatMap((enc: Buffer) =>
mergeMap((enc: Buffer) =>
key
.pipe(
decryptPrivate(enc, 'utf8')
Expand Down Expand Up @@ -469,11 +469,11 @@ describe('- Unit rsa.service.test.ts file', () => {
test('- `RsaService.loadKey().sign()` lettable operator must return an error if no private key provided', (done) => {
of(rsaService.loadKey(testKey))
.pipe(
flatMap((key: Observable<NodeRSA>) =>
mergeMap((key: Observable<NodeRSA>) =>
key
.pipe(
exportKey('public'),
flatMap((k: any) =>
mergeMap((k: any) =>
rsaService.loadKey(k)
.pipe(
sign('data')
Expand All @@ -494,11 +494,11 @@ describe('- Unit rsa.service.test.ts file', () => {
test('- `RsaService.loadKey().verify()` must return a true', (done) => {
of(rsaService.loadKey(testKey))
.pipe(
flatMap((key: Observable<NodeRSA>) =>
mergeMap((key: Observable<NodeRSA>) =>
key
.pipe(
sign('data'),
flatMap((signature: Buffer) =>
mergeMap((signature: Buffer) =>
key
.pipe(
verify('data', signature)
Expand Down
32 changes: 16 additions & 16 deletions tools/packaging.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import libraries
import { Observable, forkJoin } from 'rxjs';
import { flatMap } from 'rxjs/operators';
import { forkJoin, Observable } from 'rxjs';
import { mergeMap } from 'rxjs/operators';
import * as fs from 'fs-extra';

/**
Expand Down Expand Up @@ -34,6 +34,18 @@ class Packaging {
this._destPath = `${process.cwd()}${dest}/`;
}

/**
* Function that _copy all files in dist directory
*/
process() {
forkJoin(
this._files.map(
(fileObject: FileObject) => this._copy(fileObject.name)
)
)
.subscribe(() => null, error => console.error(error));
}

/**
* Function to copy one file
*
Expand All @@ -48,7 +60,7 @@ class Packaging {
}

// copy other files
return <Observable<any>> new Observable((observer) => {
return <Observable<any>>new Observable((observer) => {
fs.stat(`${this._srcPath}${file}`, (error, stats) => {
if (error) {
console.error('doesn\'t exist on copy =>', error.message);
Expand Down Expand Up @@ -107,7 +119,7 @@ class Packaging {
// read package.json
return readJson(`${this._srcPath}${file}`)
.pipe(
flatMap(packageObj => {
mergeMap(packageObj => {
// delete obsolete data in package.json
delete packageObj.scripts;
delete packageObj.devDependencies;
Expand All @@ -117,18 +129,6 @@ class Packaging {
})
);
}

/**
* Function that _copy all files in dist directory
*/
process() {
forkJoin(
this._files.map(
(fileObject: FileObject) => this._copy(fileObject.name)
)
)
.subscribe(() => null, error => console.error(error));
}
}

// process packaging
Expand Down

0 comments on commit 3f20358

Please sign in to comment.