|
| 1 | +import { replications } from '../../../../src/maddo/infrastructure/repositories/replication-repository.js'; |
| 2 | +import { |
| 3 | + createMaddoServer, |
| 4 | + datamartKnex, |
| 5 | + expect, |
| 6 | + generateValidRequestAuthorizationHeaderForApplication, |
| 7 | +} from '../../../test-helper.js'; |
| 8 | + |
| 9 | +describe('Maddo | Application | Acceptance | Replications', function () { |
| 10 | + describe('POST /api/replications/{replication}', function () { |
| 11 | + let server; |
| 12 | + |
| 13 | + beforeEach(async function () { |
| 14 | + const schema = (t) => { |
| 15 | + t.string('firstName').notNullable(); |
| 16 | + t.string('lastName').notNullable(); |
| 17 | + }; |
| 18 | + await datamartKnex.schema.dropTableIfExists('to-replicate'); |
| 19 | + await datamartKnex.schema.createTable('to-replicate', schema); |
| 20 | + await datamartKnex.schema.dropTableIfExists('replication'); |
| 21 | + await datamartKnex.schema.createTable('replication', schema); |
| 22 | + server = await createMaddoServer(); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should run given replication', async function () { |
| 26 | + // given |
| 27 | + const replication = 'my-replication'; |
| 28 | + await datamartKnex('to-replicate').insert([ |
| 29 | + { firstName: 'first1', lastName: 'last1' }, |
| 30 | + { firstName: 'first2', lastName: 'last2' }, |
| 31 | + ]); |
| 32 | + |
| 33 | + replications.push({ |
| 34 | + name: 'my-replication', |
| 35 | + from: ({ datawarehouseKnex }) => { |
| 36 | + return datawarehouseKnex('to-replicate').select('*'); |
| 37 | + }, |
| 38 | + to: ({ datamartKnex }, chunk) => { |
| 39 | + return datamartKnex('replication').insert(chunk); |
| 40 | + }, |
| 41 | + }); |
| 42 | + |
| 43 | + // when |
| 44 | + const response = await server.inject({ |
| 45 | + method: 'POST', |
| 46 | + url: `/api/replications/${replication}?async=false`, |
| 47 | + headers: { |
| 48 | + authorization: generateValidRequestAuthorizationHeaderForApplication( |
| 49 | + 'pix-client', |
| 50 | + 'pix-client', |
| 51 | + 'replication', |
| 52 | + ), |
| 53 | + }, |
| 54 | + }); |
| 55 | + |
| 56 | + // then |
| 57 | + expect(response.statusCode).to.equal(204); |
| 58 | + const { count } = await datamartKnex('replication').count().first(); |
| 59 | + expect(count).to.equal(2); |
| 60 | + }); |
| 61 | + }); |
| 62 | +}); |
0 commit comments