test/fixtures.js: Cleanup - data at top, images/setup at bottom

FREEBIE
This commit is contained in:
Scott Nonnenberg 2017-05-18 12:31:18 -07:00
parent 86c866738f
commit 13322c7071

View file

@ -5,32 +5,8 @@ Whisper.Fixtures = (function() {
var FRED_ID = '+14155537400'; // fbi sf
var MICHEL_ID = '+12024561111'; // twh
function dataURItoBlob(dataURI) {
var binary = atob(dataURI.split(',')[1]);
var array = [];
for (var i = 0; i < binary.length; i++) {
array.push(binary.charCodeAt(i));
}
return new Uint8Array(array).buffer;
}
var now = Date.now();
var conversations = new (Whisper.ConversationCollection.extend({
saveAll: function() {
return Promise.all(this.map(function(convo) {
return new Promise(function(resolve) {
convo.save().then(resolve);
}).then(function() {
return Promise.all(convo.messageCollection.map(function(message) {
return new Promise(function(resolve) {
message.save().then(resolve);
});
}));
});
}));
}
}))([
var conversationCollection = new Whisper.ConversationCollection([
{
name: 'Vera Zasulich',
id: VERA_ID,
@ -73,7 +49,8 @@ Whisper.Fixtures = (function() {
lastMessage: "The soul is the prison of the body."
}
]);
var Michel = conversations.get(MICHEL_ID);
var Michel = conversationCollection.get(MICHEL_ID);
Michel.messageCollection.add([
{
conversationId: MICHEL_ID,
@ -82,7 +59,144 @@ Whisper.Fixtures = (function() {
received_at: now - 3000000,
attachments: [{
contentType: 'image/jpeg',
data: dataURItoBlob("data:image/jpeg;base64,"+
data: dataURItoBlob(getImage1())
}]
},
{
conversationId: MICHEL_ID,
type: 'incoming',
body: "The soul is the prison of the body.",
sent_at: now - 1000000,
received_at: now - 1000000,
source: MICHEL_ID,
},
{
conversationId: MICHEL_ID,
type: 'incoming',
sent_at: now - 2000000,
body: "In their opinion I am a dangerous man, since I am a crypto-Marxist.",
received_at: now - 2000000,
source: MICHEL_ID,
},
]);
var Masha = conversationCollection.get(MASHA_ID);
Masha.messageCollection.add([
{
date: now - 60000,
type: 'incoming',
source: MASHA_ID,
attachments: [{
contentType: 'image/jpeg',
data: dataURItoBlob(getImage2())
}]
},
{
date: now - 5000,
type: 'outgoing',
body: "I just installed Signal Desktop!"
},
{
date: now - 4000,
type: 'outgoing',
body: "Now I can use Signal on my computer, even when my phone is off. 😄 "
},
{
date: now,
type: 'incoming',
source: MASHA_ID,
body: "I can't wait to try it!",
unread: 1
},
].map(function(m) {
return {
conversationId : MASHA_ID,
type : m.type,
body : m.body,
sent_at : m.date,
received_at : m.date,
attachments : m.attachments,
unread : m.unread,
source : m.source,
};
}));
var group = conversationCollection.add({
name: '📖 Book Club',
type: 'group',
active_at: now - 100000,
timestamp: now - 100000,
id: 'group1',
lastMessage: "See you all there!"
});
group.messageCollection.add([
{
date: now - 30000,
type: 'incoming',
body: "If you knew when you began a book what you would say at the end, do you think that you would have the courage to write it?",
source: MICHEL_ID,
},
{
date: now - 20000,
type: 'incoming',
body: "A book which has a strange knack of seeking out its fellow-revellers and enticing them on to new secret paths and dancing-places.",
source: FRED_ID
},
{
date: now - 4000,
type: 'incoming',
body: "Let's meet in the library.",
source: NESTOR_ID
},
{
date: now - 1000,
type: 'incoming',
body: "I'll be a little late.",
source: NESTOR_ID
},
{
date: now,
type: 'outgoing',
body: "See you all there!"
},
].map(function(m) {
return {
conversationId : group.id,
source : m.source,
type : m.type,
body : m.body,
sent_at : m.date,
received_at : m.date,
attachments : m.attachments,
unread : m.unread
};
}));
function dataURItoBlob(dataURI) {
var binary = atob(dataURI.split(',')[1]);
var array = [];
for (var i = 0; i < binary.length; i++) {
array.push(binary.charCodeAt(i));
}
return new Uint8Array(array).buffer;
}
conversationCollection.saveAll = function() {
return Promise.all(this.map(function(convo) {
return new Promise(function(resolve) {
convo.save().then(resolve);
}).then(function() {
return Promise.all(convo.messageCollection.map(function(message) {
return new Promise(function(resolve) {
message.save().then(resolve);
});
}));
});
}));
};
function getImage1() {
return "data:image/jpeg;base64," +
"/9j/4QAqRXhpZgAASUkqAAgAAAABAJiCAgAFAAAAGgAAAAAAAAAgICAgAAAAAP/sABFEdWNreQAB" +
"AAQAAAA8AAD/4QOdaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49" +
"Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9" +
@ -886,35 +1000,11 @@ Whisper.Fixtures = (function() {
"CTRLtr22IbipoR0I41ll0CDpXxgXVAK168BAF3tH6VI6kn+QlA1r5SorSBY46QDrXU8hrINCrbQh" +
"hUECoXjMtYdZfYAxLUc1KqRTwrzkwNvLu9YXRaHx84CrLqVNdGodT+EorFt2rjHeQFHIcTFRWcbd" +
"Aq19PDSItZrLLuo3CaQQIZzX4CQRgyNXiAYFOQeoiClrwpUcoFgkVqOPGAC1pUQKYwAHGUSBASDp" +
"CGIawp4tqDUnQyaGG3RQ1R/tJqkkakHSnCAvQMCdRzEqNCXrZBXbUU4SK//Z")
}]
},
{
conversationId: MICHEL_ID,
type: 'incoming',
body: "The soul is the prison of the body.",
sent_at: now - 1000000,
received_at: now - 1000000,
source: MICHEL_ID,
},
{
conversationId: MICHEL_ID,
type: 'incoming',
sent_at: now - 2000000,
body: "In their opinion I am a dangerous man, since I am a crypto-Marxist.",
received_at: now - 2000000,
source: MICHEL_ID,
},
]);
var Masha = conversations.get(MASHA_ID);
Masha.messageCollection.add([
{
date: now - 60000,
type: 'incoming',
source: MASHA_ID,
attachments: [{
contentType: 'image/jpeg',
data: dataURItoBlob("data:image/jpeg;base64,"+
"CGIawp4tqDUnQyaGG3RQ1R/tJqkkakHSnCAvQMCdRzEqNCXrZBXbUU4SK//Z";
};
function getImage2() {
return "data:image/jpeg;base64," +
"/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsK" +
"CwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQU" +
"FBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAKAAoADASIA" +
@ -2556,85 +2646,8 @@ Whisper.Fixtures = (function() {
"Zz0xxUJuo1xznHPrxVhwpByowOpI/lUJiRui4oFcinnSRSASD785qqYyw759hV3yk/uj0wRSeQqg" +
"enT3PNBVygAQSMHnBqNlK9Rkdh61YmJifaw5/wA80x4jxg5BzxU2NEyA8Hp+H9aBIo4z7c9aUqVJ" +
"BBJ9KQjB9h3PTpU7ljmAJI6hfSkgd7SYSRNtI9eh+tIHG7k/jTmxt9fekJroyxcRrKhniX5Oroo4" +
"Q+n0PY1TZAVHc1LDK9tKJExkdj0Psatzwx3cT3NsMEf6yLuM9x7etWveIb5fQ//Z")
}]
},
{
date: now - 5000,
type: 'outgoing',
body: "I just installed Signal Desktop!"
},
{
date: now - 4000,
type: 'outgoing',
body: "Now I can use Signal on my computer, even when my phone is off. 😄 "
},
{
date: now,
type: 'incoming',
source: MASHA_ID,
body: "I can't wait to try it!"
},
].map(function(m) {
return {
conversationId : MASHA_ID,
type : m.type,
body : m.body,
sent_at : m.date,
received_at : m.date,
attachments : m.attachments,
source : m.source,
};
}));
var group = conversations.add({
name: '📖 Book Club',
type: 'group',
active_at: now - 100000,
timestamp: now - 100000,
id: 'group1',
lastMessage: "See you all there!"
});
group.messageCollection.add([
{
date: now - 30000,
type: 'incoming',
body: "If you knew when you began a book what you would say at the end, do you think that you would have the courage to write it?",
source: MICHEL_ID,
},
{
date: now - 20000,
type: 'incoming',
body: "A book which has a strange knack of seeking out its fellow-revellers and enticing them on to new secret paths and dancing-places.",
source: FRED_ID
},
{
date: now - 4000,
type: 'incoming',
body: "Let's meet in the library.",
source: NESTOR_ID
},
{
date: now - 1000,
type: 'incoming',
body: "I'll be a little late.",
source: NESTOR_ID
},
{
date: now,
type: 'outgoing',
body: "See you all there!"
},
].map(function(m) {
return {
conversationId : group.id,
source : m.source,
type : m.type,
body : m.body,
sent_at : m.date,
received_at : m.date,
attachments : m.attachments
};
}));
"Q+n0PY1TZAVHc1LDK9tKJExkdj0Psatzwx3cT3NsMEf6yLuM9x7etWveIb5fQ//Z";
}
return conversations;
return conversationCollection;
})();