Fashlogue API update: Development of post feature for the Api

in #utopian-io6 years ago

Repository
https://github.com/fashlogue/fashlogue-api

Pull Requests

https://github.com/fashlogue/fashlogue-api/pull/12

About

The post model have been designed in such a way to register post that where sent to the block chain and the once not sent. Users would be given the opportunity to choose where to post the particular catalog. Each post contains the author, where it was posted to, the image, description and tag.

/**
 * Post Schema
 * @author Freeman Ogbiyoyo
 * @public
 */
export let PostSchema : Schema = new Schema({
  author: {
    type: String,
    default: ''
  },
  permlink : {
    type: String,
    default: null
  },
  postImage: {
    type: String,
    default: '',
    required:true
  },
  postTitle: {
    type: String,
    default: '',
    required:true
  },
  postDescription: {
    type: String,
    default: '',
    required:true
  },
  tags: {
    type: Array,
    default: ['fashlogue']
  },
  postedTo: {
    type: Array,
    default: ['fashlogue']
  },
  createdAt: {
    type: Date,
    default: new Date
  },
  modifiedAt: {
    type: Date,
    default: new Date
  }
});

PostSchema.plugin(uniqueValidator);


/**
 * PostShchemaDoc Interface
 * @author Freeman Ogbiyoyo
 * @public
 */

interface PostSchemaDoc extends IPost,
Document {
  
}

For the above schema, the following variables were initiated author, description, permlink for the blockchain and the post image.

Brief peep into the testing code for the post feature.

Testing is so important in the industry, test driven development (TDD) was carried out in this project, in our test we try as much as possible to assert the status code and the data returned by the Api. Testing the post feature, we are going to be using the npm pakage;

  • Mocha
  • Chai
  • Supertest

1 Mocha - In the project is our test runner which runs all the test file in the test directory
2 Chai- this is uses for assertions, i.e to check if was expected from the test was returned.
3 Supertest- is used for sending various request to our endpoint. supertest can also return a promise which we can hook into for our test assertion.

Here is an Integration test that edit a post in the database
In our setup we have to database; the test database and development database. Database is switched based on the node environment passed to the cross-env module.

describe('PUT api/v1/posts/:_id', ()=> {
        it('it should edit a post in the database with the id', () => {
            const post = new PostModel({
                author: 'ogbiyoyo',
                permlink : 'link',
                postImage: 'link',
                postDescription : 'hello post',
                postTitle : 'hello post',
                Tags: ['fashlogue', 'contempatory'],
                postedTo: ['fashlogue', 'steemblockchain']  
            });
            post.save((err, postres)=>{
                 return request(app)
                .put('api/v1/posts/'+ postres._id)
                .send({permlink : 'link'})
                .expect(httpStatus[200])
                .then(res=>{
                    expect(res.body.message)
                    .to
                    .be
                    .a('string');
                })
            })
        })
    })

We try to create a post in the database, then we return a promise and get hold of the id of the post that was created. Next, we send a put request to the endpoint with the id of the post as a param and send the data we want to use to to edit the one in the database.

Feature

Post Feature.

Roadmap

Add steemconntect and instagram authentication with various middlewares.

Github Account

https://github.com/ogbiyoyosky

How to Contribute?

visit the repo and create an issue.

Sort:  
  • Just a few English language issues.
    • and the once not sent. should be and the ones not sent.
    • Brief peep into should be Brief peek into
  • Looks like you decided not to use done() anymore in your tests, why?

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thank you for your review, @helo! Keep up the good work!

Hi @sirfreeman!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Congratulations @sirfreeman! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You published more than 80 posts. Your next target is to reach 90 posts.
You received more than 3000 upvotes. Your next target is to reach 4000 upvotes.

Click here to view your Board
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Do not miss the last post from @steemitboard:

SteemitBoard - Witness Update

Support SteemitBoard's project! Vote for its witness and get one more award!