|
| 1 | +// import { Cidade } from './database/models/cidade'; |
| 2 | +// import { TestBed, async } from '@angular/core/testing'; |
| 3 | +// import { AppComponent } from './app.component'; |
| 4 | +// import { DatabaseSettingsFactory } from './database/factory/database-settings-factory'; |
| 5 | +// import { DatabaseMigrationService } from './database/provider/database-migration-service'; |
| 6 | +// import { TableMapper } from './database/mapper/table-mapper'; |
| 7 | +// import { Uf } from './database/models/uf'; |
| 8 | +// import { Regiao } from './database/models/regiao'; |
| 9 | +// import { SubRegiao } from './database/models/sub-regiao'; |
| 10 | +// import { Classificacao } from './database/models/classificacao'; |
| 11 | +// import { Cliente } from './database/models/cliente'; |
| 12 | +// import { IonicDatabaseBuilderModule, WebSqlDatabaseService, Database } from 'projects/ionic-database-builder/src/public_api'; |
| 13 | + |
| 14 | +// describe('Batch Test', () => { |
| 15 | +// beforeEach(async(() => { |
| 16 | +// TestBed.configureTestingModule({ |
| 17 | +// declarations: [ |
| 18 | +// AppComponent |
| 19 | +// ], |
| 20 | +// imports: [ |
| 21 | +// IonicDatabaseBuilderModule.forRoot( |
| 22 | +// DatabaseSettingsFactory, |
| 23 | +// WebSqlDatabaseService, |
| 24 | +// DatabaseMigrationService, |
| 25 | +// { ready: () => Promise.resolve() }, |
| 26 | +// false, |
| 27 | +// true, |
| 28 | +// ) |
| 29 | +// ], |
| 30 | +// providers: [ |
| 31 | +// TableMapper |
| 32 | +// ], |
| 33 | +// }); |
| 34 | +// })); |
| 35 | + |
| 36 | +// const clienteToSave = { |
| 37 | +// codeImport: 1, |
| 38 | +// razaoSocial: void 0, |
| 39 | +// apelido: 'Apelido', |
| 40 | +// cidade: { |
| 41 | +// codeImport: 2, |
| 42 | +// nome: 'Cidade', |
| 43 | +// uf: { |
| 44 | +// codeImport: 'SC', |
| 45 | +// nome: 'Santa Catarina' |
| 46 | +// } as Uf, |
| 47 | +// subRegiao: { |
| 48 | +// codeImport: 4, |
| 49 | +// nome: 'Sub Região', |
| 50 | +// regiao: { |
| 51 | +// codeImport: 5, |
| 52 | +// nome: 'Região' |
| 53 | +// } as Regiao |
| 54 | +// } as SubRegiao, |
| 55 | +// } as Cidade, |
| 56 | +// classificacao: { |
| 57 | +// codeImport: 3, |
| 58 | +// descricao: 'Top' |
| 59 | +// } as Classificacao, |
| 60 | +// desativo: false |
| 61 | +// } as Cliente; |
| 62 | + |
| 63 | +// it('batch simple', async () => { |
| 64 | +// const database: Database = TestBed.get(Database); |
| 65 | +// const crud = await database.crud().toPromise(); |
| 66 | + |
| 67 | +// const clienteDelete = crud.delete(Cliente).compile(); |
| 68 | + |
| 69 | +// const insert = crud.insert(Cliente, clienteToSave); |
| 70 | +// const clienteInsert = insert.compile(); |
| 71 | +// expect(clienteInsert[0].params.toString()).toEqual([ |
| 72 | +// clienteToSave.codeImport, clienteToSave.razaoSocial, clienteToSave.apelido, |
| 73 | +// clienteToSave.desativo, clienteToSave.cidade.codeImport, clienteToSave.classificacao.codeImport |
| 74 | +// ].toString()); |
| 75 | +// expect(clienteInsert[0].query).toEqual('INSERT INTO Cliente (codeImport, razaoSocial, apelido, desativo, cidade_codeImport, classificacao_codeImport) VALUES (?, ?, ?, ?, ?, ?)'); |
| 76 | + |
| 77 | +// const r = await database.batch([clienteDelete[0], clienteInsert[0]]).toPromise(); |
| 78 | +// console.log("result", r); |
| 79 | + |
| 80 | +// // const insertResult = await insert.execute().toPromise(); |
| 81 | +// // expect(insertResult[0].insertId).toBeGreaterThan(0); |
| 82 | + |
| 83 | +// // const queryResultNull = await crud.query(Cliente) |
| 84 | +// // .where(where => where.isNull(x => x.razaoSocial)) |
| 85 | +// // .toList().toPromise(); |
| 86 | + |
| 87 | +// // expect(queryResultNull.length).toEqual(1); |
| 88 | +// }); |
| 89 | + |
| 90 | +// // it('Test transaction mapper insert T', async () => { |
| 91 | +// // const database: Database = TestBed.get(Database); |
| 92 | +// // const rollback = () => { |
| 93 | +// // database.rollbackTransaction().toPromise().then().catch(); |
| 94 | +// // }; |
| 95 | +// // const crud = await database.beginTransaction().toPromise(); |
| 96 | +// // try { |
| 97 | +// // const result = crud.insert(Cliente, clienteToSave).compile(); |
| 98 | +// // expect(result[0].params.toString()).toEqual([ |
| 99 | +// // clienteToSave.codeImport, clienteToSave.razaoSocial, clienteToSave.apelido, |
| 100 | +// // clienteToSave.desativo, clienteToSave.cidade.codeImport, clienteToSave.classificacao.codeImport |
| 101 | +// // ].toString()); |
| 102 | +// // expect(result[0].query).toEqual('INSERT INTO Cliente (codeImport, razaoSocial, apelido, desativo, cidade_codeImport, classificacao_codeImport) VALUES (?, ?, ?, ?, ?, ?)'); |
| 103 | +// // const commitResult = await database.commitTransaction().toPromise(); |
| 104 | +// // expect(commitResult).toEqual(true); |
| 105 | +// // } catch (e) { |
| 106 | +// // rollback(); |
| 107 | +// // } |
| 108 | +// // }); |
| 109 | +// }); |
0 commit comments