Skip to content

Commit c8e1f1a

Browse files
committed
DEV-1185_Crear-pipeline-ngx-jsonapi auto-commit
1 parent f3390d4 commit c8e1f1a

File tree

12 files changed

+3290
-2878
lines changed

12 files changed

+3290
-2878
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/

angular.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,8 @@
133133
"@schematics/angular:directive": {
134134
"prefix": "bc"
135135
}
136+
},
137+
"cli": {
138+
"analytics": false
136139
}
137140
}

jest.lib.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = {
1515
],
1616
globals: {
1717
'ts-jest': {
18-
tsConfig: 'projects/ngx-jsonapi-lib/tsconfig.spec.json'
18+
tsconfig: 'projects/ngx-jsonapi-lib/tsconfig.spec.json'
1919
},
2020
stringifyContentPathRegex: true
2121
},

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"prettier-scss:show": "prettier --parser scss --single-quote --tab-width 4 --print-width 140 --single-quote true \"**/*.scss\"",
3737
"prettier:fix": "prettier \"demo/**/*.{ts,scss,json,md}\" \"projects/**/*.{ts,scss,json,md}\" --write",
3838
"prettier:check": "prettier \"demo/**/*.{ts,scss,json,md}\" \"projects/**/*.{ts,scss,json,md}\" --list-different",
39-
"precommit": "lint-staged"
39+
"precommit": "lint-staged",
40+
"build:jsonapi": "npx ng-packagr -p projects/ngx-jsonapi-lib/ng-package.json"
4041
},
4142
"lint-staged": {
4243
"*.ts": [
@@ -94,7 +95,9 @@
9495
]
9596
},
9697
"resolutions": {
97-
"jest-environment-jsdom": "27.4.6"
98+
"minimatch": "9.0.0",
99+
"jest-environment-jsdom": "27.4.6",
100+
"esbuild-wasm": "0.14.54"
98101
},
99102
"devDependencies": {
100103
"@angular-devkit/build-angular": "16.2.0",
@@ -139,7 +142,7 @@
139142
"eslint-plugin-prettier": "5.0.0",
140143
"eslint-plugin-rxjs": "5.0.0",
141144
"eslint-plugin-unicorn": "48.0.1",
142-
"fake-indexeddb": "2.1.1",
145+
"fake-indexeddb": "4",
143146
"faker": "4.1.0",
144147
"fs-extra": "2.1.2",
145148
"gh-pages": "1.1.0",

projects/ngx-jsonapi-lib/src/lib/cloned-resource.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { IClonedResource } from './interfaces/cloned-resource';
77

88
export class ClonedResource<T extends Resource> extends Resource implements IClonedResource {
99
private parent: Resource;
10-
public attributes: T['attributes'];
11-
public relationships: T['relationships'];
10+
public attributes: T['attributes'] = undefined as any;
11+
public relationships: T['relationships'] = {} as any;
1212

1313
public constructor(resource: T) {
1414
super();

projects/ngx-jsonapi-lib/src/lib/service.spec.ts

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,3 @@
1-
// Mock optimizado para DexieDataProvider en memoria
2-
class InMemoryDataProvider {
3-
private collections: Record<string, any> = {};
4-
private elements: Record<string, any> = {};
5-
6-
async getElement(key: string, table: string) {
7-
const store = table === 'collections' ? this.collections : this.elements;
8-
if (!(key in store)) throw new Error(key + ' not found.');
9-
return store[key];
10-
}
11-
async getElements(keys: string[], table: string) {
12-
const store = table === 'collections' ? this.collections : this.elements;
13-
return keys.map((k) => store[k]).filter(Boolean);
14-
}
15-
async saveElements(elements: any[], table: string) {
16-
const store = table === 'collections' ? this.collections : this.elements;
17-
elements.forEach((e) => {
18-
store[e.key] = e.content;
19-
});
20-
}
21-
async updateElements(key_start_with: string, changes: any, table: string) {
22-
const store = table === 'collections' ? this.collections : this.elements;
23-
Object.keys(store).forEach((k) => {
24-
if (k.startsWith(key_start_with)) delete store[k];
25-
});
26-
}
27-
}
28-
29-
jest.mock('./data-providers/dexie-data-provider', () => ({
30-
DexieDataProvider: InMemoryDataProvider
31-
}));
32-
331
import { StoreService } from './sources/store.service';
342
import { JsonRipper } from './services/json-ripper';
353
import { ClassProvider, Injector } from '@angular/core';
@@ -1578,9 +1546,7 @@ describe('service.get()', () => {
15781546
(bookData.data as IDataResource).relationships = {
15791547
author: { data: { id: 'author_1', type: 'authors' } }
15801548
};
1581-
test_response_subject.next(
1582-
new HttpResponse({ body: bookData })
1583-
);
1549+
test_response_subject.next(new HttpResponse({ body: bookData }));
15841550
let book_clone: ClonedResource<Book> = await booksService.getClone('1').toPromise();
15851551
let original_book: Book = await booksService.get('1').toPromise();
15861552
expect(book_clone.source).toBe(original_book.source);
@@ -1590,7 +1556,10 @@ describe('service.get()', () => {
15901556
expect(book_clone.relationships.author).toBeUndefined();
15911557
} else {
15921558
const cloneAuthorId = book_clone.relationships.author.data ? book_clone.relationships.author.data.id : undefined;
1593-
const originalAuthorId = original_book.relationships.author && original_book.relationships.author.data ? original_book.relationships.author.data.id : undefined;
1559+
const originalAuthorId =
1560+
original_book.relationships.author && original_book.relationships.author.data
1561+
? original_book.relationships.author.data.id
1562+
: undefined;
15941563
expect(cloneAuthorId).toBe(originalAuthorId);
15951564
expect(book_clone.relationships.author.loaded).toBe(original_book.relationships.author.loaded);
15961565
}

projects/ngx-jsonapi-lib/src/lib/services/converter.spec.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@ import { Http as JsonapiHttpImported } from '../sources/http.service';
88
import { HttpClient, HttpHandler, HttpRequest, HttpEvent, HttpResponse } from '@angular/common/http';
99
import { BehaviorSubject, Observable } from 'rxjs';
1010
import { IResourcesByType } from '../interfaces/resources-by-type';
11+
import { Service } from '../service';
12+
import { Resource } from '../resource';
1113

1214
class HttpHandlerMock implements HttpHandler {
15+
private subject: BehaviorSubject<HttpResponse<any>>;
1316
public handle(req: HttpRequest<any>): Observable<HttpEvent<any>> {
14-
let subject: BehaviorSubject<HttpResponse<any>> = new BehaviorSubject(new HttpResponse());
15-
16-
return subject.asObservable();
17+
this.subject = new BehaviorSubject(new HttpResponse());
18+
return this.subject.asObservable();
19+
}
20+
public complete() {
21+
if (this.subject) {
22+
this.subject.complete();
23+
}
1724
}
1825
}
1926

@@ -34,6 +41,25 @@ let core: Core = new Core(
3441
injector
3542
);
3643

44+
class SomeTypeResource extends Resource {
45+
public type = 'sometype';
46+
public id = '';
47+
public attributes: any = {};
48+
public relationships: any = {};
49+
public links: any = {};
50+
public meta: any = {};
51+
}
52+
class SomeTypeService extends Service<SomeTypeResource> {
53+
public type = 'sometype';
54+
public resource = SomeTypeResource;
55+
public constructor() {
56+
super();
57+
this.register();
58+
}
59+
}
60+
const someTypeService = new SomeTypeService();
61+
someTypeService.register();
62+
3763
describe('Converter', () => {
3864
it('json_array2resources_array_by_type(array) should be converted to IResourcesByType', () => {
3965
let converted: IResourcesByType = Converter.json_array2resources_array_by_type([

projects/ngx-jsonapi-lib/src/lib/services/json-ripper.spec.ts

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,3 @@
1-
// Mock optimizado para DexieDataProvider en memoria
2-
class InMemoryDataProvider {
3-
private collections: Record<string, any> = {};
4-
private elements: Record<string, any> = {};
5-
6-
async getElement(key: string, table: string) {
7-
const store = table === 'collections' ? this.collections : this.elements;
8-
if (!(key in store)) throw new Error(key + ' not found.');
9-
return store[key];
10-
}
11-
async getElements(keys: string[], table: string) {
12-
const store = table === 'collections' ? this.collections : this.elements;
13-
return keys.map((k) => store[k]).filter(Boolean);
14-
}
15-
async saveElements(elements: any[], table: string) {
16-
const store = table === 'collections' ? this.collections : this.elements;
17-
elements.forEach((e) => {
18-
store[e.key] = e.content;
19-
});
20-
}
21-
async updateElements(key_start_with: string, changes: any, table: string) {
22-
const store = table === 'collections' ? this.collections : this.elements;
23-
Object.keys(store).forEach((k) => {
24-
if (k.startsWith(key_start_with)) delete store[k];
25-
});
26-
}
27-
}
28-
29-
jest.mock('../data-providers/dexie-data-provider', () => ({
30-
DexieDataProvider: InMemoryDataProvider
31-
}));
32-
331
import { Resource } from '../resource';
342
import { JsonRipper } from './json-ripper';
353
import { DocumentCollection } from '../document-collection';
@@ -60,19 +28,6 @@ describe('JsonRipper for resources', () => {
6028
// ...agrega más si los tests lo requieren
6129
} as any;
6230

63-
beforeAll(() => {
64-
// Sobrescribe el constructor de JsonRipper para que use el mock en memoria
65-
JsonRipper.prototype.constructor = function () {
66-
this.dataProvider = new InMemoryDataProvider();
67-
this.enabled = true;
68-
};
69-
});
70-
71-
beforeEach(() => {
72-
// Reemplazar el dataProvider por el mock en memoria
73-
JsonRipper.prototype['dataProvider'] = new InMemoryDataProvider();
74-
});
75-
7631
it('A resource is converted to objects for a DataProvider', () => {
7732
jest.spyOn(Resource.prototype, 'getService').mockReturnValue(minimalServiceMock);
7833

@@ -205,10 +160,6 @@ describe('JsonRipper for collections', () => {
205160
// ...agrega más si los tests lo requieren
206161
} as any;
207162

208-
beforeEach(() => {
209-
JsonRipper.prototype['dataProvider'] = new InMemoryDataProvider();
210-
});
211-
212163
it('A ripped collection saved via DataProvider is converted to a Json', async () => {
213164
jest.spyOn(Resource.prototype, 'getService').mockReturnValue(minimalServiceMock);
214165

projects/ngx-jsonapi-lib/tsconfig.spec.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"extends": "../../tsconfig.json",
44
"compilerOptions": {
55
"outDir": "../../out-tsc/spec",
6+
"esModuleInterop": true,
67
"types": ["jest"]
78
},
89
"include": ["**/*.spec.ts", "**/*.d.ts"]

setup-jest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
declare var global: any;
22

33
import 'jest-preset-angular/setup-jest';
4+
import 'fake-indexeddb/auto';
5+
46
global['CSS'] = null;
57

68
/**

0 commit comments

Comments
 (0)