Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Publication Authors
casper.test.begin('Verifying Publication Authors entity migration', function suite(test) {
// Load the JSON document.
var json = require(json_dir + '/' + datestamp + '/PUB_AUTHORS2.json');
var pubAuthorJoin = require(json_dir + '/' + datestamp + '/PUB_AUTHORS.json');
var currentRow = 0;
// Run the test.
casper.run(check);
// Process all rows in the JSON document.
function check () {
if (json[currentRow] && currentRow < json.length) {
verifyData.call(this, json[currentRow]);
currentRow++;
this.run(check);
} else {
this.test.done();
}
}
// Verify that Drupal data exists using the API.
function verifyData(row) {
// Loop through join table.
function getPubIdsForAuthId(authId) {
var pubs = [];
for (var i = 0; i < pubAuthorJoin.length; i++) {
if (pubAuthorJoin[i][1] == authId) {
pubs.push(pubAuthorJoin[i][3]);
}
}
return pubs;
}
var aid = row[0];
var label = row[1];
var lastname = row[2];
var initials = row[3];
var rid = row[4];
var retry = 0;
// Get all Pub IDs for the author from the pubAuthorJoin var.
var pubsForAuthor = getPubIdsForAuthId(aid);
this.thenOpen(link + '/api/publication-author/' + aid,
function then(response) {
this.test.comment('Checking content returned by /api/publication-author/' + aid + ' (' + currentRow + ' out of ' + json.length + ')');
if (response.status !== 200) {
if (retry > 3) {
this.test.comment('Retried the URL 4 times, got response ' + response.status);
this.test.assert(false, 'Failed to load ' + cleanString(label) + ' with author id ' + aid);
// Reset the retry counter.
retry = 0;
return;
}
// Retry.
this.test.comment('Got a ' + response.status + ' error; retrying');
currentRow = currentRow - 1;
retry++;
this.wait(5000);
return;
}
this.test.assertTextExists('Successfully located Drupal entity', 'Success message present');
this.test.assertTextDoesntExist('We found more than one entity matching', 'No duplicate content found.');
this.test.assertTitleMatch(new RegExp(label.split(' ')[0], 'i'), 'Titles match');
this.test.assertTextExists(lastname, 'Last name is present.');
if (initials !== '') {
this.test.assertTextExists(initials, 'Initials present.');
}
this.test.assertTextExists(aid, 'Publication Author ID exists.');
// Check Pub IDs.
if (pubsForAuthor.length > 0) {
for (var i = 0; i < pubsForAuthor.length; i++) {
this.test.assertTextExists(pubsForAuthor[i], 'Pub ID ' + pubsForAuthor[i] + ' is linked.');
}
}
// Check external ID.
if (rid !== '') {
this.test.assertTextExists(rid, 'External ID present.');
}
this.wait(500);
},
function timeout() {
this.test.assert(false, 'Timeout! Failed to load author id ' + aid);
},
10000
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment