Skip to content

Commit

Permalink
feat: Get all built-in fields updateable with all tests passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-coster committed Aug 17, 2021
1 parent fb9431b commit b7582ea
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ As environment variables:
- ✔ Fetch a Card directly by its ID
- ✔ Fetch a Card directly by its user-visible "sequential ID"
- ✔ Compose a card URL
- 🔜 Update a Card's main fields
- Update a Card's built-in fields
- 🔜 Update a Card's Custom Fields
- 🔜 Add an attachment to a card
- ❓ Find card by field value, including Custom Fields
Expand Down
12 changes: 7 additions & 5 deletions src/lib/entities/BravoCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,15 @@ export class BravoCard extends BravoEntity<DataFavroCard> {
async update(data?: FavroApiParamsCardUpdate) {
// TODO: Handle Custom Fields
// TODO: Handle adding Attachments
const updated = await this._client.updateCardById(
this.cardId,
data || this.updateBuilder.toJSON(),
);
data ||= this.updateBuilder.toJSON();
// Replace the update builder immediately, since
// we then have to wait for the update to occur
// the the user might want to start building a new update
// before that returns.
this._updateBuilder = new BravoCardUpdateBuilder();
const updated = await this._client.updateCardById(this.cardId, data);
// Update this card!
this._data = updated._data;
this._updateBuilder = new BravoCardUpdateBuilder();
return this;
}

Expand Down
69 changes: 62 additions & 7 deletions src/test/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,20 @@ describe('BravoClient', function () {
expect(byCardId!.equals(foundCard), 'can fetch by sequentialId').to.be
.true;
});
xit('can update a card', async function () {
it('can update a cards built-in fields', async function () {
/**
* Must include updates to all of:
* - name
* - description
* - favroAttachments
* - Members (regular and custom)
* Must be able to set/unset all of:
* - ✔ name
* - ✔ description
* - ✔ startDate
* - ✔ dueDate
* - ✔ archived
* - ✔ tags
* - ✔ assignment
* - ✔ assignmentCompletion
* - ✔ favroAttachments
*
* - Members (custom)
* - Tags (regular and custom)
* - Text
* - Number
Expand All @@ -266,9 +273,57 @@ describe('BravoClient', function () {
* - Link
* - Date
*/
const users = await client.listFullUsers();
const user = users[0];
const newName = 'NEW NAME';
const newDescription = '# New Description\n\nHello!';
// testCard.updateBuilder.setName(newName).setDescription(newDescription).se;
const testDate = new Date();
const tagName = 'totally-real-tag';
testCard.updateBuilder
.setName(newName)
.setDescription(newDescription)
.assign([user.userId])
// // Cannot attach a card to self! (Get that error message
// // when we try, implying that the update would otherwise
// // work.
// .addFavroAttachments([
// { itemCommonId: testCard.cardCommonId, type: 'card' },
// ])
.addTagsByName([tagName])
.completeAssignment([user.userId])
.setStartDate(testDate)
.setDueDate(testDate)
.archive();
await testCard.update();
expect(testCard.detailedDescription).to.equal(newDescription);
expect(testCard.name).to.equal(newName);
expect(testCard.assignments[0].userId).to.equal(user.userId);
expect(testCard.assignments[0].completed).to.equal(true);
expect(testCard.tags[0]).to.be.a('string');
expect(testCard.dueDate).to.eql(testDate);
expect(testCard.startDate).to.eql(testDate);
expect(testCard.archived).to.equal(true);

// Unset unsettable values
testCard.updateBuilder
.unarchive()
.removeTagsByName([tagName])
.uncompleteAssignment([user.userId])
.unsetDueDate()
.unsetStartDate();
await testCard.update();
expect(testCard.archived).to.equal(false);
expect(testCard.dueDate).to.be.null;
expect(testCard.startDate).to.be.null;
expect(testCard.tags).to.be.empty;
expect(testCard.assignments[0].completed).to.be.false;

// Need to unset the assigned user separately,
// since we wanted to check that we could uncomplete
// that user's assignment in the last step.
testCard.updateBuilder.unassign([user.userId]);
await testCard.update();
expect(testCard.assignments).to.be.empty;
});
xit('can unset card fields', async function () {});

Expand Down

0 comments on commit b7582ea

Please sign in to comment.