0

I have managed to successfully implement forward/ backward pagination along with sorting in backend with dynamoDb query.However i am stuck in providing paginated data or sorted data.

Is there a way to load dummy data during test?

my code for testing

test('should paginate backward and forward', async () => {
    const data = {
      Items: [
        {
          convertedUrl: 'https://xxxx.awssensei.tk/ddddd',
          createdAt: '2021-11-04T05:50:14.180Z',
          originalUrl: 'https://aws.com',
          updatedAt: '2021-11-04T05:58:12.659Z',
        },
        {
          convertedUrl: 'https://xxxx.awssensei.tk/bbbbb',
          createdAt: '2021-11-04T05:50:43.818Z',
          originalUrl: 'https://fb.com',
          updatedAt: '2021-11-04T05:57:42.704Z',
        },
        {
          convertedUrl: 'https://xxx.awssensei.tk/eeeee',
          createdAt: '2021-11-04T05:50:55.121Z',
          originalUrl: 'https://google.com',
          updatedAt: '2021-11-04T05:58:21.141Z',
        },
        {
          convertedUrl: 'https://xxxx.awssensei.tk/aaaaa',
          createdAt: '2021-11-04T05:51:06.603Z',
          originalUrl: 'https://instagram.com',
          updatedAt: '2021-11-04T05:57:14.750Z',
        },
      ],
    };

    sandbox
      .stub(AWS.DynamoDB.DocumentClient.prototype, 'query')
      .returns({ promise: () => data });

    const app = require('../app');
    const response = await request(app)
      .get('/users/auth-user/urls?sort_by=createdAt')
      .set('Authorization', `Bearer ${token}`);
    expect(response.body.history.length).toBe(4);
  });
Lin Du
  • 88,126
  • 95
  • 281
  • 483
Jatin Mehrotra
  • 9,286
  • 4
  • 28
  • 67

0 Answers0