Fashlogue API update: Development of post feature for the Api

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.

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now