<commit_before>describe('KeyChangeListener', function() {
  var phone_number_with_keychange = '+13016886524';  // nsa
  var oldkey = libsignal.crypto.getRandomBytes(33);
  var newkey = libsignal.crypto.getRandomBytes(33);
  var store;

  before(function() {
    storage.put('safety-numbers-approval', false);
  });

  after(function() {
    storage.remove('safety-numbers-approval');
  });

  beforeEach(function() {
    store = new SignalProtocolStore();
    Whisper.KeyChangeListener.init(store);
    return store.saveIdentity(phone_number_with_keychange, oldkey);
  });

  afterEach(function() {
    return store.removeIdentityKey(phone_number_with_keychange);
  });

  describe('When we have a conversation with this contact', function() {
    var convo = new Whisper.Conversation({ id: phone_number_with_keychange, type: 'private'});
    before(function() {
      ConversationController.add(convo);
      return convo.save();
    });

    after(function() {
      convo.destroyMessages();
      return convo.destroy();
    });

    it('generates a key change notice in the private conversation with this contact', function(done) {
      convo.on('newmessage', function() {
        return convo.fetchMessages().then(function() {
          var message = convo.messageCollection.at(0);
          assert.strictEqual(message.get('type'), 'keychange');
          done();
        });
      });
      return store.isTrustedIdentity(phone_number_with_keychange, newkey);
    });
  });


  describe('When we have a group with this contact', function() {
    var convo = new Whisper.Conversation({ id: 'groupId', type: 'group', members: [phone_number_with_keychange] });
    before(function() {
      ConversationController.add(convo);
      return convo.save();
    });
    after(function() {
      convo.destroyMessages();
      return convo.destroy();
    });

    it('generates a key change notice in the group conversation with this contact', function(done) {
      convo.on('newmessage', function() {
        return convo.fetchMessages().then(function() {
          var message = convo.messageCollection.at(0);
          assert.strictEqual(message.get('type'), 'keychange');
          done();
        });
      });
      return store.isTrustedIdentity(phone_number_with_keychange, newkey);
    });

  });

});<commit_msg>Clean up key change listener tests<commit_after>describe('KeyChangeListener', function() {
  var phoneNumberWithKeyChange = '+13016886524';  // nsa
  var oldKey = libsignal.crypto.getRandomBytes(33);
  var newKey = libsignal.crypto.getRandomBytes(33);
  var store;

  before(function() {
    storage.put('safety-numbers-approval', false);
  });

  after(function() {
    storage.remove('safety-numbers-approval');
  });

  beforeEach(function() {
    store = new SignalProtocolStore();
    Whisper.KeyChangeListener.init(store);
    return store.saveIdentity(phoneNumberWithKeyChange, oldKey);
  });

  afterEach(function() {
    return store.removeIdentityKey(phoneNumberWithKeyChange);
  });

  describe('When we have a conversation with this contact', function() {
    var convo = new Whisper.Conversation({ id: phoneNumberWithKeyChange, type: 'private'});
    before(function() {
      ConversationController.add(convo);
      return convo.save();
    });

    after(function() {
      convo.destroyMessages();
      return convo.destroy();
    });

    it('generates a key change notice in the private conversation with this contact', function(done) {
      convo.on('newmessage', function() {
        return convo.fetchMessages().then(function() {
          var message = convo.messageCollection.at(0);
          assert.strictEqual(message.get('type'), 'keychange');
          done();
        });
      });
      return store.isTrustedIdentity(phoneNumberWithKeyChange, newKey);
    });
  });


  describe('When we have a group with this contact', function() {
    var convo = new Whisper.Conversation({ id: 'groupId', type: 'group', members: [phoneNumberWithKeyChange] });
    before(function() {
      ConversationController.add(convo);
      return convo.save();
    });
    after(function() {
      convo.destroyMessages();
      return convo.destroy();
    });

    it('generates a key change notice in the group conversation with this contact', function(done) {
      convo.on('newmessage', function() {
        return convo.fetchMessages().then(function() {
          var message = convo.messageCollection.at(0);
          assert.strictEqual(message.get('type'), 'keychange');
          done();
        });
      });
      return store.isTrustedIdentity(phoneNumberWithKeyChange, newKey);
    });

  });

});
{'fraction_non_alphanumeric': 0.13873330461008185, 'fraction_numerical': 0.007324429125376993, 'mean_word_length': 3.4388145315487573, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7534881', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1314, 'n_words': 273}