백엔드개발자의 자세+ test,api

jadive study·2022년 10월 12일
0

API는 무엇을 의미하나요?

API의 맥락에서 애플리케이션이라는 단어는 고유한 기능을 가진 모든 소프트웨어를 나타낸다 인터페이스는 두 애플리케이션 간의 서비스 계약이라고 할 수 있다. 이 계약은 요청과 응답을 사용하여 두 애플리케이션이 서로 통신하는 방법을 정의한다. API 문서에는 개발자가 이러한 요청과 응답을 구성하는 방법에 대한 정보를 담는다.

개발자의 자세

→library 관점을 가지고 검색하는자세가 중요

→서버는 만들어진 서버기반위에 원하는기능을 붙일려고 노력

->공통화된 모듈들을 만들고 main context에 붙힌다

->룰을 잡는것이 중요하다

->package 어떤파일을 start할것인지

테스트

-개발자 테스트(테스트 코드)

-기본적인 기능 단위

-유닛(단위)테스트

—Mock(가짜)를 을 사용한다

-통합테스트

—실제에 가까운 환경을 사용한다

성능적인 단위

-부하테스트

—Jmeter 외부 툴로 사용도 가능

개발자가 수동테스트

-예시: postman 등, UI 조작 등

서비스관점

-QA엔지니어 테스트(게임쪽은 필수)

const { describe } = require('../models/user');
const { isLoggedIn, isNotLoggedIn} = require('./middlewares');

describe('isLoggedIn', () => {
    const res ={
        status: jest.fn(() => res),
        send: jest.fn(),
    };
    const next =jest.fn();

    test('로그인 되어있으면 isLoggedIn이 next를 호출해야 함', () => {

        //given

        //when

        //then

    });

    test('로그인 되어있지 않으면 isLoggedIn이 에러를 응답해야 함', () => {

    });
});

-> 패턴을 찾고 패턴에 맞게 적용시키는것이 개발자의 역할


describe('isLoggedIn', () => {
    const res ={
        status: jest.fn(() => res),
        send: jest.fn(),
    };
    const next =jest.fn();

    test('로그인 되어있으면 isLoggedIn이 next를 호출해야 함', () => {

        //given
        const req ={
            isAuenticated : jest.fn(()=> true)
        }

        //when
        isLoggedIn(req, res, next)

        //then
        expect(next).toBeCaaledTimes(1)
    });

  
 ---------------------------------------------------------


const { describe } = require('../models/user');
const { isLoggedIn, isNotLoggedIn} = require('./middlewares');

describe('isLoggedIn', () => {
    const res ={
        status: jest.fn(() => res),
        send: jest.fn(),
    };
    const next =jest.fn();

    test('로그인 되어있으면 isLoggedIn이 next를 호출해야 함', () => {

        //given
        const req ={
            isAuenticated : jest.fn(()=> true)
        }
        //when
        isLoggedIn(req, res, next)

        //then
        expect(next).toBeCaaledTimes(1)
    });

    test('로그인 되어있지 않으면 isLoggedIn이 에러를 응답해야 함', () => {

    });
});



test('로그인 되어있지 않으면 isLoggedIn이 에러를 응답해야 함', () => {
        //given
        const req ={
            isAuenticated : jest.fn(()=> false)
        //when
        isLoggedIn(req, res, next)
        
        //then
        expect(next).toBeCaaledTimes(1)



test('사용자를 찾아 팔로잉을 추가하고 success를 응답해야 함', async () => {
  //   User.findOne.mockReturnValue(Promise.resolve({
  //     addFollowing(id) {
  //       return Promise.resolve(true);
  //     }
  //   }));
  //   await addFollowing(req, res, next);
  //   expect(res.send).toBeCalledWith('success');
  // });

  //given
    // await addFollowing(req, res, next);
    //   expert(res.send).toBeCalled('success');


  //when

  

  //then

  test('사용자를 못 찾으면 next(error)를 호출함', async () => {
    // const error = '사용자 못 찾음';
    // User.findOne.mockReturnValue(Promise.reject(error));
    // await addFollowing(req, res, next);
    // expect(next).toBeCalledWith(error);

    // await addFollowing(req,res,next);
    // expect(res,send).toBeCalledwith('no User');
  });
});
profile
개발 메모창고

0개의 댓글