const main = async () => { for (let i = 0; i < tables.length; i++) { const data = await db.select().from(tables[i]); const yaml = YAML.stringify(data); await fs.writeFile(path.join(__dirname, 'seeds', 'data', `${tables[i]}.yml`), yaml); } db.destroy(); }
(async () => { const dbPath = __dirname + "/data.sqlite"; await fs.remove(dbPath); await fs.ensureFile(dbPath); const knex = require("./knex"); await knex.migrate.latest(); await knex.seed.run(); if (isCli()) { await knex.destroy(); } })()
mRepo.getForEdit(1).then((res) => { console.log(res); }) .catch((err) => { console.log(err); }) .finally (() => { db.destroy(); });
describe('ONG', () => { beforeEach(async () => { await connection.migrate.rollback(); await connection.migrate.latest(); }) afterAll(async () => { await connection.destroy(); }); it('should be able to create a new ONG', async () => { const responce = await request(app) .post('/ongs') .send({ name: "APAD", email: "cpetecs123@gmail.com", whatsapp: "11111111111", city: "Santana de Parnaiba", uf: "SP" }); expect(responce.body).toHaveProperty('id'); expect(responce.body.id).toHaveLength(8); }) });
const createTable = async config => { // Connect to the database config.host = `/cloudsql/${config.connectionName}`; const knex = Knex({client: 'pg', connection: config}); // Create the "votes" table try { await knex.schema.createTable('votes', table => { table.bigIncrements('vote_id').notNull(); table.timestamp('time_cast').notNull(); table.specificType('candidate', 'CHAR(6) NOT NULL'); }); console.log(`Successfully created 'votes' table.`); return knex.destroy(); } catch (err) { console.error(`Failed to create 'votes' table:`, err); if (knex) { knex.destroy(); } } }
// Prompt the user for connection details prompt.get(FIELDS, async (err, config) => { if (err) { console.error(err); return; } // Connect to the database const knex = Knex({client: 'pg', connection: config}); // Create the "visits" table try { await knex.schema.createTable('visits', table => { table.increments(); table.timestamp('timestamp'); table.string('userIp'); }); console.log(`Successfully created 'visits' table.`); return knex.destroy(); } catch (err) { console.error(`Failed to create 'visits' table:`, err); if (knex) { knex.destroy(); } } });
describe('Session', () => { beforeEach(async () => { await connection.migrate.rollback(); await connection.migrate.latest(); await connection.seed.run(); }, 10000); afterEach(async () => { await connection.migrate.rollback(); }); afterAll(async () => { await connection.destroy(); }); it('should be able to login as an ONG', async () => { // entrando como a ONG const response = await request(app) .post('/sessions') .send({ email: 'apad@apad.com.br', password: '123456789' }); expect(response.body).toHaveProperty("expire_at") expect(response.body).toHaveProperty("name") }); });
await connection.destroy(); });
db.knex.destroy(); process.exit(0); });
await connection.destroy(); });
// Prompt the user for connection details prompt.get(FIELDS, async (err, config) => { if (err) { console.error(err); return; } // Connect to the database const knex = Knex({client: 'mysql', connection: config}); // Create the "visits" table try { await knex.schema.createTable('visits', table => { table.increments(); table.timestamp('timestamp'); table.string('userIp'); }); console.log(`Successfully created 'visits' table.`); } catch (err) { console.error(`Failed to create 'visits' table:`, err); } finally { if (knex) { knex.destroy(); } } });
await connection.destroy(); });
await connection.destroy(); });
describe('NGO', () => { beforeEach(async () => { await connection.migrate.rollback() await connection.migrate.latest() }) afterAll(async () => { await connection.destroy() }) it('should be able to create a new NGO', async () => { const response = await request(app).post('/ngos') .send({ name: "Test", email: "contato@test.com.br", whatsapp: "5541933333333", city: "Curitiba", uf: "PR" }) expect(response.body).toHaveProperty('id') expect(response.body.id).toHaveLength(8) }) })