// tests for update_team_submission
// Generated by serverless-jest-plugin

const mod = require('../handler');

const jestPlugin = require('serverless-jest-plugin');

const { lambdaWrapper } = jestPlugin;
const adder = lambdaWrapper.wrap(mod, { handler: 'create_team' });
const wrapped = lambdaWrapper.wrap(mod, { handler: 'update_team_submission' });
const getter = lambdaWrapper.wrap(mod, { handler: 'get_team_submission' });
const AWS = require('aws-sdk');

const add = {
    body: JSON.stringify({
        "team_name": "updater test",
        "project_submitted": false
    })
};

//invalid get request with no team_id
const invalid_request = {
    body: JSON.stringify({
        "id": "this is not team_id",
        "project_submitted": true
    })
};

describe('update_team_submission', () => {
  beforeAll((done) => {
    done();
  });

  it('Correctly updates team project submission', async () => {
    const added = await adder.run(add);
    const myId = JSON.parse(added.body).id;

    const update_mentorship = {
      body: JSON.stringify({
        team_id: myId,
        project_submitted: true,
      }),
    };
    return await wrapped.run(update_mentorship).then(async (response) => {
      expect(response).toBeDefined();
      expect(response).toHaveProperty('statusCode', 200);

      const getRequest = {
        queryStringParameters: {
          team_id: myId,
        },
      };

      const result = await getter.run(getRequest);
      expect(JSON.stringify(JSON.parse(result.body)[0].project_submitted)).toMatch("true");
    });
  });
  it('Successfully rejects request to update a teams info without id', async() =>{
    return await wrapped.run(invalid_request).then(async (response) => {
        expect(response).toBeDefined();
        expect(response).toHaveProperty('statusCode', 500);
    }); 
});
});