How to use the server/db.none function in server

To help you get started, we’ve selected a few server examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 1ven / do / test / server / routes / boards-routes.spec.js View on Github external
it('/boards/remove should remove board', (done) => {
        const boardId = 2;

        db.none("INSERT INTO boards (title) values ('board 1'), ('board 2'), ('board 3')")
            .then(() => {
                request(app)
                .post('/boards/remove')
                .send({
                    id: boardId
                })
                .expect('Content-Type', /json/)
                .expect(200)
                .end((err, res) => {
                    if (err) { done(err); }

                    const body = res.body;
                    const expectedBody = {
                        success: true
                    };
github 1ven / do / test / server / api / base-api.spec.js View on Github external
it('should remove entry', () => {
            return db.none("INSERT INTO test_1 (title) values ('entry 1'), ('entry 2'), ('entry 3')")
                .then(() => testApi1.remove(2))
                .then(() => db.query('SELECT * FROM test_1'))
                .then(result => {
                    const rows = result.reduce((acc, row) => {
                        acc[row.id] = row;
                        return acc;
                    }, {});

                    assert.property(rows, 1);
                    assert.notProperty(rows, 2);
                    assert.property(rows, 3);
                });
        });
    });
github 1ven / do / test / server / models / Card.spec.js View on Github external
it('should remove color id from card', () => {
      const cardId = shortid.generate();
      return db.none(
        `INSERT INTO cards(id, text, colors)
        VALUES ($1, 'test card', array[1, 3])`,
        [cardId]
      )
        .then(() => {
          return Card.removeColor(cardId, 3);
        })
        .then(() => {
          return db.one(
            `SELECT colors FROM cards WHERE id = $1`,
            [cardId]
          );
        })
        .then(({ colors }) => {
          assert.deepEqual(colors, [1]);
        });
github 1ven / do / test / server / models / Trash.spec.js View on Github external
it('should return empty array if user has no deleted entries', () => {
      const emptyUserId = shortid.generate();
      const boardId = shortid.generate();
      return db.none(
        `INSERT INTO users(id, username, email, hash, salt)
        VALUES ($1, 'emptyuser', 'emptyuser@test.com', 'hash', 'salt');
        INSERT INTO boards (id, title) VALUES ($2, 'some board');
        INSERT INTO users_boards VALUES ($1, $2)`,
        [emptyUserId, boardId]
      )
        .then(() => {
          return Trash.find(user3Id, 1)
            .then(result => {
              assert.deepEqual(result, {
                pages_length: 0,
                trash: [],
              });
            });
        });
    });
github 1ven / do / test / server / api / lists-api.spec.js View on Github external
it('should get full list by given id', () => {
            return db.none(`
                INSERT INTO lists (title, cards)
                    values ('test list 1', NULL), ('test list 2', ARRAY[1, 2, 3]), ('test list 3', NULL);
                INSERT INTO cards (text)
                    values ('test card 1'), ('test card 2'), ('test card 3');
            `)
                .then(() => listsApi.getFull(2))
                .then(list => {
                    const expected = {
                        id: 2,
                        title: 'test list 2',
                        cards: [
                            { id: 1, text: 'test card 1' },
                            { id: 2, text: 'test card 2' },
                            { id: 3, text: 'test card 3' }
                        ]
                    };
github 1ven / do / test / server / routes / api / activity.spec.js View on Github external
return new Promise((resolve, reject) => {
                const now = Math.floor(Date.now() / 1000 + i);
                db.none(`
                  INSERT INTO activity (created_at, entry_id, user_id, entry_table, action)
                  VALUES ($1, $2, $3, 'cards', 'Updated')
                  `, [now, cardId, i < 20 ? user2Id : userId]).then(resolve, reject);
              });
            });
github 1ven / do / test / server / models / Comment.spec.js View on Github external
function setup() {
  return db.none(
    `INSERT INTO users (id, username, email, hash, salt)
    VALUES ($1, 'testuser', 'testuser@test.com', 'hash', 'salt');
    INSERT INTO cards (id, text) VALUES ($2, 'test card');
    INSERT INTO comments (id, text) VALUES ($3, 'test comment 1'), ($4, 'test comment 2');
    INSERT INTO cards_comments VALUES ($2, $3), ($2, $4);
    INSERT INTO users_comments VALUES ($1, $3), ($1, $4);`,
    [userId, cardId, commentId, comment2Id]
  );
}
github 1ven / do / test / server / models / Base.spec.js View on Github external
beforeEach(() => {
        return db.none(`DROP TABLE IF EXISTS
            boards,
            boards_lists,
            lists,
            lists_cards,
            cards,
            users
            CASCADE
        `)
            .then(() => db.none(`
                CREATE TABLE boards(
                    id serial PRIMARY KEY,
                    title text NOT NULL,
                    hidden text
                );
                CREATE TABLE lists(
                    id serial PRIMARY KEY,
github 1ven / do / test / server / models / Base.spec.js View on Github external
function insert() {
            return db.none(`
                INSERT INTO boards (title) VALUES ('test board 1'), ('test board 2'), ('test board 3')
            `)
        };
github 1ven / do / test / server / models / Activity.spec.js View on Github external
return new Promise((resolve, reject) => {
          const now = Math.floor(Date.now() / 1000 + i);
          db.none(`
            INSERT INTO activity (created_at, entry_id, user_id, entry_table, action)
            VALUES ($1, $2, $3, 'cards', 'Updated')`,
            [now, cardId, i < 20 ? userId : user2Id]
          )
            .then(resolve, reject);
        });
      });