<commit_before>const assert = require('assert');

const redis = require('redis');

const client = redis.createClient();

// this is how redis errors are handled
client.on('error', (err) => {
  console.log(err);
});

const SocialDB = require('../index.js');

const sd = new SocialDB(client);

describe('Testing SocialDB', () => {
  before(() => {
    client.flushdb();
  });

  describe('.follow()', () => {
    describe('initial request', () => {
      it('should add users to `requested` and `pending`', (done) => {
        sd.follow(1, 11).then(() => {
          client.zcard(`user:${1}:requested`, (err, count) => {
            assert.equal(count, 1);
            client.zcard(`user:${11}:pending`, (err2, count2) => {
              assert.equal(count2, 1);
              done();
            });
          });
        });
      });
    });

    describe('reciprocal request', () => {
      it('should remove users from `requested` and `pending`', (done) => {
        sd.follow(11, 1).then(() => {
          client.zcard(`user:${1}:requested`, (err, count) => {
            assert.equal(count, 0);
            client.zcard(`user:${11}:pending`, (err2, count2) => {
              assert.equal(count2, 0);
              done();
            });
          });
        });
      });

      it('should add users to `accepted`', (done) => {
        client.zcard(`user:${1}:accepted`, (err, count) => {
          assert.equal(count, 1);
          client.zcard(`user:${11}:accepted`, (err2, count2) => {
            assert.equal(count2, 1);
            done();
          });
        });
      });
    });
  });

  describe('.unfollow()', () => {
    it('should mututally unfollow two users', (done) => {
      sd.unfollow(1, 11).then(() => {
        client.zcard(`user:${1}:accepted`, (err, count) => {
          assert.equal(count, 0);
          client.zcard(`user:${11}.accepted`, (err2, count2) => {
            assert.equal(count2, 0);
            done();
          });
        });
      });
    });
  });

  describe('.requested()', () => {
    it('should get a list of requested followers', (done) => {
      sd.requested(1).then((users) => {
        assert.equal(users.length, 0);
        done();
      });
    });

    it('should get a list of requested followers', (done) => {
      sd.follow(1, 11).then(() => {
        sd.requested(1).then((users) => {
          assert.equal(users.length, 1);
          done();
        });
      });
    });
  });

  describe('.pending()', () => {
    it('should get a list of pending followers', (done) => {
      sd.pending(1).then((users) => {
        assert.equal(users.length, 0);
        done();
      });
    });

    it('should get a list of pending followers', (done) => {
      sd.follow(1, 11).then(() => {
        sd.pending(11).then((users) => {
          assert.equal(users.length, 1);
          done();
        });
      });
    });
  });

  describe('.accepted()', () => {
    client.flushdb(() => {
      it('should get a list of accepted followers', (done) => {
        sd.accepted(1).then((users) => {
          assert.equal(users.length, 0);
          done();
        });
      });
    });

    it('should get a list of accepted followers', (done) => {
      sd.follow(1, 11).then(() => {
        sd.follow(11, 1).then(() => {
          sd.accepted(11).then((users) => {
            assert.equal(users.length, 1);
            sd.accepted(1).then((users2) => {
              assert.equal(users2.length, 1);
              done();
            });
          });
        });
      });
    });
  });

  describe('.friends()', () => {
    client.flushdb(() => {
      it('should get a list of accepted followers', (done) => {
        sd.friends(1).then((users) => {
          assert.equal(users.length, 0);
          done();
        });
      });
    });

    it('should get a list of accepted followers', (done) => {
      sd.follow(1, 11).then(() => {
        sd.follow(11, 1).then(() => {
          sd.friends(11).then((users) => {
            assert.equal(users.length, 1);
            sd.friends(1).then((users2) => {
              assert.equal(users2.length, 1);
              done();
            });
          });
        });
      });
    });
  });
});
<commit_msg>Fixed premature DB flushing in test<commit_after>const assert = require('assert');

const redis = require('redis');

const client = redis.createClient();

// this is how redis errors are handled
client.on('error', (err) => {
  console.log(err);
});

const SocialDB = require('../index.js');

const sd = new SocialDB(client);

describe('Testing SocialDB', () => {
  before(() => {
    client.flushdb();
  });

  describe('.follow()', () => {
    describe('initial request', () => {
      it('should add users to `requested` and `pending`', (done) => {
        sd.follow(1, 11).then(() => {
          client.zcard(`user:${1}:requested`, (err, count) => {
            assert.equal(count, 1);
            client.zcard(`user:${11}:pending`, (err2, count2) => {
              assert.equal(count2, 1);
              done();
            });
          });
        });
      });
    });

    describe('reciprocal request', () => {
      it('should remove users from `requested` and `pending`', (done) => {
        sd.follow(11, 1).then(() => {
          client.zcard(`user:${1}:requested`, (err, count) => {
            assert.equal(count, 0);
            client.zcard(`user:${11}:pending`, (err2, count2) => {
              assert.equal(count2, 0);
              done();
            });
          });
        });
      });

      it('should add users to `accepted`', (done) => {
        client.zcard(`user:${1}:accepted`, (err, count) => {
          assert.equal(count, 1);
          client.zcard(`user:${11}:accepted`, (err2, count2) => {
            assert.equal(count2, 1);
            done();
          });
        });
      });
    });
  });

  describe('.unfollow()', () => {
    it('should mututally unfollow two users', (done) => {
      sd.unfollow(1, 11).then(() => {
        client.zcard(`user:${1}:accepted`, (err, count) => {
          assert.equal(count, 0);
          client.zcard(`user:${11}.accepted`, (err2, count2) => {
            assert.equal(count2, 0);
            done();
          });
        });
      });
    });
  });

  describe('.requested()', () => {
    it('should get a list of requested followers', (done) => {
      sd.requested(1).then((users) => {
        assert.equal(users.length, 0);
        done();
      });
    });

    it('should get a list of requested followers', (done) => {
      sd.follow(1, 11).then(() => {
        sd.requested(1).then((users) => {
          assert.equal(users.length, 1);
          done();
        });
      });
    });
  });

  describe('.pending()', () => {
    it('should get a list of pending followers', (done) => {
      sd.pending(1).then((users) => {
        assert.equal(users.length, 0);
        done();
      });
    });

    it('should get a list of pending followers', (done) => {
      sd.follow(1, 11).then(() => {
        sd.pending(11).then((users) => {
          assert.equal(users.length, 1);
          done();
        });
      });
    });
  });

  describe('.accepted()', () => {
    client.flushdb(() => {
      it('should get a list of accepted followers', (done) => {
        sd.accepted(1).then((users) => {
          assert.equal(users.length, 0);
          done();
        });
      });
    });

    it('should get a list of accepted followers', (done) => {
      sd.follow(1, 11).then(() => {
        sd.follow(11, 1).then(() => {
          sd.accepted(11).then((users) => {
            assert.equal(users.length, 1);
            sd.accepted(1).then((users2) => {
              assert.equal(users2.length, 1);
              done();
            });
          });
        });
      });
    });
  });

  describe('.friends()', () => {
    it('should get a list of accepted followers', (done) => {
      client.flushdb(() => {
        sd.friends(1).then((users) => {
          assert.equal(users.length, 0);
          done();
        });
      });
    });

    it('should get a list of accepted followers', (done) => {
      sd.follow(1, 11).then(() => {
        sd.follow(11, 1).then(() => {
          sd.friends(11).then((users) => {
            assert.equal(users.length, 1);
            sd.friends(1).then((users2) => {
              assert.equal(users2.length, 1);
              done();
            });
          });
        });
      });
    });
  });
});

{'fraction_non_alphanumeric': 0.21487603305785125, 'fraction_numerical': 0.020306965761511215, 'mean_word_length': 1.8217854763491006, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 107, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4064821', 'n_tokens_mistral': 2730, 'n_tokens_neox': 2604, 'n_words': 473}