* chore(package): update jasmine to version 3.0.0 Closes #4547 * Fixes failing tests for jasmine 3.0 Starting 3.0, done(something) will fail * Update tests so they dont leverage var, but let and const With jasmine 3.0, the randomization engine was making the test fails because of the scope of `var` * Remove randomizer * Use same adapter for PG tests, drop table to ensure the tests dont side effect
118 lines
3.8 KiB
JavaScript
118 lines
3.8 KiB
JavaScript
import PostgresStorageAdapter from '../src/Adapters/Storage/Postgres/PostgresStorageAdapter';
|
|
const databaseURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
|
|
|
|
const getColumns = (client, className) => {
|
|
return client.map('SELECT column_name FROM information_schema.columns WHERE table_name = $<className>', { className }, a => a.column_name);
|
|
};
|
|
|
|
const dropTable = (client, className) => {
|
|
return client.none('DROP TABLE IF EXISTS $<className:name>', { className });
|
|
}
|
|
|
|
describe_only_db('postgres')('PostgresStorageAdapter', () => {
|
|
const adapter = new PostgresStorageAdapter({ uri: databaseURI })
|
|
beforeEach(() => {
|
|
return adapter.deleteAllClasses();
|
|
});
|
|
|
|
it('schemaUpgrade, upgrade the database schema when schema changes', done => {
|
|
const client = adapter._client;
|
|
const className = '_PushStatus';
|
|
const schema = {
|
|
fields: {
|
|
"pushTime": { type: 'String' },
|
|
"source": { type: 'String' },
|
|
"query": { type: 'String' },
|
|
},
|
|
};
|
|
|
|
adapter.createTable(className, schema)
|
|
.then(() => getColumns(client, className))
|
|
.then(columns => {
|
|
expect(columns).toContain('pushTime');
|
|
expect(columns).toContain('source');
|
|
expect(columns).toContain('query');
|
|
expect(columns).not.toContain('expiration_interval');
|
|
|
|
schema.fields.expiration_interval = { type:'Number' };
|
|
return adapter.schemaUpgrade(className, schema);
|
|
})
|
|
.then(() => getColumns(client, className))
|
|
.then(columns => {
|
|
expect(columns).toContain('pushTime');
|
|
expect(columns).toContain('source');
|
|
expect(columns).toContain('query');
|
|
expect(columns).toContain('expiration_interval');
|
|
done();
|
|
})
|
|
.catch(error => done.fail(error));
|
|
});
|
|
|
|
it('schemaUpgrade, maintain correct schema', done => {
|
|
const client = adapter._client;
|
|
const className = 'Table';
|
|
const schema = {
|
|
fields: {
|
|
"columnA": { type: 'String' },
|
|
"columnB": { type: 'String' },
|
|
"columnC": { type: 'String' },
|
|
},
|
|
};
|
|
|
|
adapter.createTable(className, schema)
|
|
.then(() => getColumns(client, className))
|
|
.then(columns => {
|
|
expect(columns).toContain('columnA');
|
|
expect(columns).toContain('columnB');
|
|
expect(columns).toContain('columnC');
|
|
|
|
return adapter.schemaUpgrade(className, schema);
|
|
})
|
|
.then(() => getColumns(client, className))
|
|
.then(columns => {
|
|
expect(columns.length).toEqual(3);
|
|
expect(columns).toContain('columnA');
|
|
expect(columns).toContain('columnB');
|
|
expect(columns).toContain('columnC');
|
|
done();
|
|
})
|
|
.catch(error => done.fail(error));
|
|
});
|
|
|
|
it('Create a table without columns and upgrade with columns', done => {
|
|
const client = adapter._client;
|
|
const className = 'EmptyTable';
|
|
dropTable(client, className).then(() => adapter.createTable(className, {}))
|
|
.then(() => getColumns(client, className))
|
|
.then(columns => {
|
|
expect(columns.length).toBe(0);
|
|
|
|
const newSchema = {
|
|
fields: {
|
|
"columnA": { type: 'String' },
|
|
"columnB": { type: 'String' }
|
|
},
|
|
};
|
|
|
|
return adapter.schemaUpgrade(className, newSchema);
|
|
})
|
|
.then(() => getColumns(client, className))
|
|
.then(columns => {
|
|
expect(columns.length).toEqual(2);
|
|
expect(columns).toContain('columnA');
|
|
expect(columns).toContain('columnB');
|
|
done();
|
|
})
|
|
.catch(done);
|
|
});
|
|
});
|
|
|
|
describe_only_db('postgres')('PostgresStorageAdapter shutdown', () => {
|
|
it('handleShutdown, close connection', () => {
|
|
const adapter = new PostgresStorageAdapter({ uri: databaseURI });
|
|
expect(adapter._client.$pool.ending).toEqual(false);
|
|
adapter.handleShutdown();
|
|
expect(adapter._client.$pool.ending).toEqual(true);
|
|
});
|
|
});
|